Possible Duplicate:
How to calculate how many years passed since a given date in Ruby?
I am trying to convert a datestamp taken from the database into value indicating how many years old a person is. I am sure this easy, but I can’t seem to figure it out.
Assuming the datestamp is being retrieved as a DateTime value:
birth_dateis a mock value for what you should be retrieving from your database. The first value is years, the second is fractional years.Alternately, you can do it this way:
This adjusts in case the person hasn’t had their birthday yet. For instance, tweaking the birthday: