Skip to content

Instantly share code, notes, and snippets.

@alex-gable
Created April 6, 2019 18:33
Show Gist options
  • Save alex-gable/bd1217d751f0a2fc1bf38ec4d7a3bbfa to your computer and use it in GitHub Desktop.
Save alex-gable/bd1217d751f0a2fc1bf38ec4d7a3bbfa to your computer and use it in GitHub Desktop.
date differences using lubridate
library(lubridate)
bday <- lubridate::as_date("2000-09-15")
today <- lubridate::as_date("2018-09-15")
tomorrow <- lubridate::as_date("2018-09-16")
bday%--%today / lubridate::years(1)
# [1] 18
as.numeric(as.duration(bday%--%today)) / (60*60*24*365.25)
# [1] 17.99863
bday%--%tomorrow / lubridate::years(1)
# [1] 18.00274q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment