question regarding adding / subtracting days from given date

2005-07-14 Thread Mandira
Hi ,
Is there is any easy way around to add / subtract days from any given date.
I am new to perl , i don't have Date/Calc.pm .
The way i could figure out is 
 get date
 convert it to epoch 
 add / subtract seconds for desired number of days (consideriung fact of 
1900 add / sub in year )
 conver it back to local time
 Is there is any other way around for addiing subtracting days in date ?
  Thanks in Advance
Mandira


Re: question regarding adding / subtracting days from given date

2005-07-14 Thread Rick Measham

Mandira wrote:

Hi ,
Is there is any easy way around to add / subtract days from any given date.
I am new to perl , i don't have Date/Calc.pm .
The way i could figure out is 


get date
convert it to epoch 
add / subtract seconds for desired number of days (consideriung fact of 


1900 add / sub in year )


conver it back to local time


 Is there is any other way around for addiing subtracting days in date ?
  Thanks in Advance
Mandira



G'day Mandira, most people on this list would suggest installing the 
DateTime suite if you want to work with dates and times 'correctly'. Do 
you have shell access to the machine you're running perl on? If so, run 
cpan and install datetime:


shell cpan
cpan install DateTime
cpan install DateTime::TimeZone

If not, let us know what access you have an we can help with that.

Once you have DateTime, here's a simple recipe for you:

my $datetime = DateTime-new(
year  = 2005,
month = 7,
day   = 15
);

print $datetime-datetime; # Outputs 2005-07-15T00:00:00

$datetime-add( days = 4 );

print $datetime-datetime; # Outputs 2005-11-15T00:00:00


Cheers!
Rick Measham