in reply to How to substract date in perl?
Just subtract three days worth of seconds from the argument to localtime and you'll get the date three days ago. It'll account for February and any other weird months that come along too. ;-)my $time = time(); my ($d1, $m1, $y1) = (localtime($time))[3..5]; $y1 += 1900; $m1 += 1; $time -= 24*3600*3; # this is three days of seconds my ($d2, $m2, $y2) = (localtime($time))[3..5]; $y2 += 1900; $m2 += 1; print "$y1\_$m1\_$d1\n"; print "$y2\_$m2\_$d2\n";
Update: forgot to add 1 to the month.
-caedes
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to substract date in perl?
by Abigail-II (Bishop) on Feb 26, 2003 at 09:39 UTC | |
by caedes (Pilgrim) on Feb 26, 2003 at 09:45 UTC | |
by Abigail-II (Bishop) on Feb 26, 2003 at 09:56 UTC |