Re: Calculate date
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 31 Jan 2007 08:10:14 -0800
On Jan 31, 10:18 am, "Shan" <Shani...@xxxxxxxxx> wrote:
I need help calculting a dta.
My data is in the following format
10
89
17
10
The above means 10 days ago, 89 days ago, 17 days ago, etc from
01.16/2007. I need to claculate the exact dates.
so 10 should be conversted to 01/06/2007 and so forth.
The easiest way is going to be with Date::Calc's Add_Delta_Days
function:
$ perl -MDate::Calc=Add_Delta_Days -wle'
for my $delta (10, 89, 17) {
my ($y, $m, $d) = Add_Delta_Days(2007, 1, 16, -$delta);
print "1/16/2007 - $delta days = ", join "/", $m, $d, $y;
}
'
1/16/2007 - 10 days = 1/6/2007
1/16/2007 - 89 days = 10/19/2006
1/16/2007 - 17 days = 12/30/2006
If you have an aversion to installing the module for some reason,
you'll have to do the calculations manually: use Time::Local's
timelocal() function to get a timestamp for 1/16/2007, then subtract
from that the number of seconds that are in your given number of days,
then use the builtin localtime() to go from that newtime stamp back to
a series of seconds, minutes, hours, days, months, years, making sure
you take into account the odd values (year is actually year-1900,
month is actually month-1), not to mention leap-year problems....
Date::Calc takes care of all of the above for you. It's far easier.
Paul Lalli
.
- Follow-Ups:
- Re: Calculate date
- From: Shan
- Re: Calculate date
- References:
- Calculate date
- From: Shan
- Calculate date
- Prev by Date: regexp
- Next by Date: Re: regexp
- Previous by thread: Calculate date
- Next by thread: Re: Calculate date
- Index(es):
Relevant Pages
|