You can also do Time.now.year - other_date.year
Cheers, -Roy -----Original Message----- From: rubyonrails-talk@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of gsterndale Sent: Thursday, November 20, 2008 11:26 PM To: Ruby on Rails: Talk Subject: [Rails] Re: Getting the number of years between two dates I've done so in the past with the Time class. ((Time.now-past_date)/1.year).round On Nov 20, 10:42 pm, "James Englert" <[EMAIL PROTECTED]> wrote: > Hey, > I need to get the number of years (as a number) between two dates. > Here is what I have as a helper. > > # Returns the number of years between now and the specified date. > def years_ago(date) > dateDifference = DateTime.now - date > results =Date.day_fraction_to_time(dateDifference) > return results[0] / 24 / 365; > end > > I'm sure there is a better way to do this. What is it? > > Thanks, > Jim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---