I am trying to define a customized function to get the difference in years between two dates,
Here's what I got so far:
library(lubridate)
## function to get the difference between years ##
set_dif_years <- function(end_date, start_date){
return(lubridate :: year(end_date)- lubridate :: year(start_date))
}
## testing function ##
set_dif_years(end_date=format(as.Date('01/08/2019', format='%d/%m/%Y'), "%d/%m/%Y"),
start_date=format(as.Date('28/08/2019', format='%d/%m/%Y'), "%d/%m/%Y"))
Console output:
# -27
For this case expected function output should be 0.
However I can't figure out what is missing in the function,
Is there any way to adjust the function in order to get desired result?