A year is 365.25 days in ruby
November 6th, 2009
1 2 3 4 |
>> 1.year.to_i / 1.day.to_i => 365 >> 1.year.to_f / 1.day.to_f => 365.25 |
Which makes quick and dirty calculations like age = (Time.now - birthdate) / 1.year slightly more accurate than one might expect.
1 Response to “A year is 365.25 days in ruby”
Sorry, comments are closed for this article.
November 6th, 2009 at 07:32 PM It would be nice if Rails did this properly like Date does: Date.parse('2010-11-06') - Date.parse('2009-11-06') # => Rational(365, 1) Date.parse('2012-11-06') - Date.parse('2011-11-06') # => Rational(366, 1)