Skip to content

Instantly share code, notes, and snippets.

@fpcMotif
Forked from lhmet/months_between_dates.R
Created October 29, 2018 15:20
Show Gist options
  • Save fpcMotif/9b6115a08c95c6b76eec6b4a7aca962c to your computer and use it in GitHub Desktop.
Save fpcMotif/9b6115a08c95c6b76eec6b4a7aca962c to your computer and use it in GitHub Desktop.
Number of months between two dates
library(lubridate)
dates <- c("2011-01-17", "2009-11-21")
p <- as.period( interval( ymd(dates), Sys.Date() ) )
year(p)*12 + month(p)
interval(dates, today()) %/% months(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment