Skip to content

Instantly share code, notes, and snippets.

@lguardiola
Created October 16, 2012 17:52
Show Gist options
  • Save lguardiola/3900863 to your computer and use it in GitHub Desktop.
Save lguardiola/3900863 to your computer and use it in GitHub Desktop.
Date extension to calculate diff in years between two dates
# override date class
class Date
def self.years_from(date)
r = today.year - date.year
r-=1 if today.month < date.month
r-=1 if today.month == date.month && today.day < date.day
r
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment