[EMAIL PROTECTED] wrote:

> 
> Gurus,
> 
> A simple one: what's the best, quickest, way to get the difference
> between two dates. They're both in the same format: "YYYYMMDD". One of
> them gets ginned up into that format starting from a call to time (that
> is, $x = time; stuff happens to $x; $y ends up "20051031";), the other's
> read in as a string from a file.

Some will say to use one of the Date modules, but I prefer to just
convert to epoch time and subtract.

use Time::Local;

$_ = '20051031';
$y = substr $_, 0, 4;
$m = substr $_, 4, 2;
$d = substr $_, 6, 2;
my $epoch = timelocal (0, 0, 0, $d, $m-1, $y-1900);

Do the same with the other time and subtract to get seconds of diff.
Divide by 86400 to get days of diff.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to