From: Antonio Cangiano Date: 2006-02-02T06:37:42+09:00 Subject: Re: relative dates charlie bowman wrote: > today = Time.now > > how can I do this? "last_week = 7.days.ago" > > I know the above won't work, but how can I get the date of last week? > Hi Charlie, you could define something like this: class Integer def weeks self * 7.days end def days self * 24.hours end def hours self * 60.minutes end def minutes self * 60 end def ago(time = Time.now) time - self end end puts 7.days.ago #=> Mon Jan 23 01:50:09 GMT 2006 puts 1.weeks.ago #=> Mon Jan 23 01:50:09 GMT 2006 Of course you can alias days with day, weeks with week, add months, years and so on. You can also add extra methods like Rails does (until, since, from_now, etc...) Cheers, Antonio -- Antonio Cangiano My Ruby blog: http://www.antoniocangiano.com