[Bloomington-normal-pm] FW: Perl Quiz-of-the-Week #2 SPOILER
Phil Winans
pawinan at ilstu.edu
Thu Oct 24 08:54:08 CDT 2002
Here's what I came up with... works with dates between 1902 and 2037.
use Time::Local;
use constant SECONDS_IN_DAY => 60 * 60 * 24;
use strict;
sub days_diff
{
my @dates = @_;
my %months;
@months{ qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) }
= 0..11;
my @times = map {
my ($mon, $day, $year) = (split)[1..3];
timegm(0, 0, 0, $day, $months{$mon}, $year);
} @dates;
return ( ($times[1] - $times[0]) / SECONDS_IN_DAY );
}
print days_diff("Wed Oct 16 2002", "Wed Oct 23 2002"), "\n";
print days_diff("Wed Oct 16 2002", "Tue Oct 16 2001"), "\n";
More information about the Bloomington-normal-pm
mailing list