Skip to content

Instantly share code, notes, and snippets.

@nmenag
Created January 22, 2016 16:24
Show Gist options
  • Select an option

  • Save nmenag/2635103dda97605ece44 to your computer and use it in GitHub Desktop.

Select an option

Save nmenag/2635103dda97605ece44 to your computer and use it in GitHub Desktop.
Method for calculate the years and the months between two dates
def date_diff(date1, date2)
month = (date2.year * 12 + date2.month) - (date1.year * 12 + date1.month)
month.divmod(12)
end
#for get the years
date_diff(date, Date.today)[0]
#for get the months
date_diff(date, Date.today)[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment