# What date was so many months and years before - Page 2

•  Subject
• Author
• Posted on

## Re: What date was so many months and years before

BM> DateTime is the 'big guns' when it comes to date and time
BM> manipulation in Perl. It does everything, and it does it right,
BM> but it's also quite a large chunk of code. IME it's usually
BM> simpler just to use it anyway, though.

Simpler and wiser; the first time your code screws up because the
legislative entity in your country changed the dates for Daylight
Savings Time or British Summer Time or whatever it's called in your
locale, you will have wasted more time than just using DateTime.

Assuming you got the time change right in the first place, that is.  I
worked for a place (years ago) that had custom date handling code.
Twice a year we could count on customer service nightmares because no
two systems handled daylight savings time in the same way, never mind
correctly.

Charlton

--
Charlton Wilbur
cwilbur@chromatico.net

## Re: What date was so many months and years before

El 01/12/13 00:57, gamo escribió:

Here's all what my brain could make, using wour subs:

sub delta_days{
my (\$d1, \$m1, \$y1, \$d2, \$m2, \$y2) = @_;
my \$delta =0;
my \$ystep =1;
\$ystep = -1 if \$y1>\$y2;
for (my \$i=\$y1; \$i!=\$y2; \$i += \$ystep) {
\$delta += (365+leap_year(\$i))*\$ystep;
}
my \$mstep = 1;
\$mstep = -1 if \$m1>\$m2;
for (my \$j=\$m1; \$j!=\$m2; \$j += \$mstep){
\$delta += days_per_month(\$j)*\$mstep;
}
\$delta += (\$d2-\$d1);
return \$delta;
}

TIA