From: "Nathaniel S. H. Brown" Date: 2006-01-30T14:31:55+09:00 Subject: Re: relative dates You might want to check out RUNT: http://runt.rubyforge.org/ DateBox might also be worth a gander: http://datebox.inimit.com -Nb ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Nathaniel S. H. Brown http://nshb.net ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > -----Original Message----- > From: A LeDonne [mailto:aledonne.listmail@gmail.com] > Sent: January 29, 2006 9:15 PM > To: ruby-talk ML; cbowmanschool@yahoo.com > Subject: Re: relative dates > > On 1/29/06, charlie bowman wrote: > > Thanks, I had no idea that it was so simple in Ruby! > > > > > > today = Time.now > > puts (today - 7) > > Careful! > > If you're using Time, you're subtracting SECONDS: > irb(main):001:0> today = Time.now > => Mon Jan 30 00:11:51 EST 2006 > irb(main):002:0> puts( today - 7 ) > Mon Jan 30 00:11:44 EST 2006 > => nil > > That's why I included the " require 'date' " in my example, > and suggested that you could use DateTime if you needed times. > > > > > > > I thought I would have to write the method myself! > > > > > > > > > > > > > > A LeDonne wrote: > > > On 1/29/06, Cameron McBride wrote: > > >> > how can I do this? "last_week = 7.days.ago" > > >> > > >> or subtract in seconds: > > >> last_week = today - 7*24*60*60 > > >> > > >> Cameron > > >> > > > > > > This is probably going to be easier with Date than with Time... > > > > > > irb(main):001:0> require 'date' > > > => true > > > irb(main):002:0> now = Date.today; now.strftime() => "2006-01-29" > > > irb(main):003:0> last_week = now - 7; last_week.strftime() => > > > "2006-01-22" > > > > > > If you are concerned about times, you can use DateTime in > place of > > > Date above. > > > > > > -A >