It is tricky to calculate time differences accurately, especially perhaps years. Sources such as Wikipedia talk about an average length of a Gregorian year of g = 365.2425 days, taking account for leap years (not yet for leap seconds, though, which are not regular). Anyway, we could assume g as the average length of a year, neglecting the actual number of leap days in our time difference and define a function add_yr()
that should be reasonably valid for dates after October 15, 1582.
add_yr <- \(d, y) as.Date(d) + y * 365.2425
(prior to R4.1.* use this code: add_yr <- function(d, y) as.Date(d) + y * 365.2425
)
This shows that we need to insert -5.495
instead of -5.5
to get OP's desired date ("2015-11-21"
).
add_yr("2021-05-21", -5.495)
# [1] "2015-11-21"
add_yr("2021-05-21", -5.5)
# [1] "2015-11-20"
The gain in accuracy is almost 2 days in this case:
(5.5 - 5.495) * 365.2425
# [1] 1.826212