Age of person - ActiveSupport

this will not work?

def age (time)   return (DateTime.now - time).years end

Justin Ko wrote:

Elad Meidar - Creopolis.com wrote: > this will not work? > > def age (time) > return (DateTime.now - time).years > end

Nope. Can you?

-- Posted via http://www.ruby-forum.com/.

This is probably overkill if this is the only unit based math you want to do but...

gem install ruby-units

require 'ruby-units' age = 'years'.since(birthday) # where birthday is either a Time, DateTime, or string of a date

if you install and require the 'Chronic' gem, you can pass all sorts of funky stuff..

require 'chronic' 'days'.until 'monday' #=> 1.48601 days

_Kevin