in reply to Comparing two dates and finding out number of days

POSIX includes a mktime function wich takes (seconds, minutes, hours, day (0 based), month (o based), year (1900 based)) and returns the epoch seconds. So if you use it on each date to get there seconds, then subtract and divide by the number of seconds in a day you get the number of days seperating two days.

use strict; use warnings; my $first = "11/15/2007"; my $second = "12/25/2007"; use POSIX qw/mktime/; sub days_between { my ($start, $end) = @_; my ($m1, $d1, $y1) = split ("/", $start); my ($m2, $d2, $y2) = split ("/", $end); my $diff = mktime(0,0,0, $d2-1, $m2-1, $y2 - 1900) - mktime(0 +,0,0, $d1-1, $m1-1, $y1 - 1900); return $diff / (60*60*24); } print "Between $first and $second there are ", days_between($first, $s +econd), " days\n";

I have no idea if this handles leap anything but I feel pretty safe in assuming that it does ;)


___________
Eric Hodges