Date calculation down to the minute


I'm subtracting date of birth from date of death to calculate age using
the following formula. (Actually, this formula is using,
because date of death is in another Controller and I haven't figured
out how to access it from where date of birth lives. Ideas?) Anyway,
this formula works fine if the age is "years", but in the case of ages
less than a year, it just returns 0. I'd like for it to return
minutes, days, weeks, months, or years -- depending on the age. Ideas
and suggestions always welcome!! Thank you! ~Ali

def age

    @age ||= begin
      a = read_attribute(:age)
        if a.nil?
          m = read_attribute(:dob)
          if not m.nil?
            now =
            now.year - dob.year - (dob.to_time.change(:year =>
now.year) > now ? 1 : 0)
   end - dob.to_time == age in seconds

You can get anything else from there.

Hope that helps !