I currently have this less-than-ideal solution:
def years_between_dates(date_from, date_to)
((date_to.to_time - date_from.to_time) / 1.year.seconds).floor
end
The calculation doesn't have to be exact (w/ leap years etc), but does need to be fairly accurate and take into account months. 3.8 years should return 3 years, hence the floor
.
I am converting to_time
to account for both Date
, Time
, and DateTime
.
I can't help but think there is a more succinct way of doing the above.