From: Osuka Adartse Date: 2003-12-27T15:45:46+09:00 Subject: Re: newbie question on how to subtract two dates. Ruby Ruby wrote: > I have a file with a file name of the form filename.yymmdd, where yy=two digits year, mm=two digits month and dd=two digits day. For example, perf.030906 indicates 03=year 2003, 09=September and 06=the sixth day of the month (September 06, 2003). > > This file contains performance data collected during the day and each system contains one file per day. We have few dozen systems collecting this data. > > Every days, around 1:00 AM I have to take the file for the previous day and copy it to a central server where the new file will have the name: hostname.perf.yymmdd. The question I have is how do I subtract two dates. For example, if: > > today=010104 > > yesterday=123103 > > Is there a ruby method that will allow me to perform something like: today - x and get yesterday? > > Thank you > > > --------------------------------- > Do you Yahoo!? > Protect your identity with Yahoo! Mail AddressGuard You could use something like this: require 'date' puts today=Date.today #=>2003-12-27 puts tomorrow=Date.new(2003,12,28) #=>2003-12-28 puts today-1 #=>2003-12-26 puts today+30 #=>2004-01-26 cheers Adartse