I'd like to calculate a difference between two dates in years with decimal values. Let's say we have "1978-08-25" and "2014-02-05" (%Y-%m-%d). How can I calculate the difference between these two dates in years with decimal values (ie. not just 35 years, but 35.95...years)? Thank you in advance.
Asked
Active
Viewed 4,538 times
3
-
1check out the `lubridate` package – tim riffe Feb 06 '14 at 00:08
-
1somewhat close: `as.integer(as.Date("2014-02-05") - as.Date("1978-08-25")) / 365.25` – flodel Feb 06 '14 at 00:21
-
1`0.95` years is not a well defined quantity of time. – hadley Feb 06 '14 at 01:03
2 Answers
1
It's probably worth noting that this really can't be answered definitively (as @hadley alluded to). Even the base difftime
function in R only allows the options of:
...units = c("auto", "secs", "mins", "hours", "days", "weeks"))
No months, no years, because they are not definite values. Having said that, you can closely approximate something sensible using @flodel's method in the comments.

thelatemail
- 91,185
- 12
- 128
- 188