# Assume the following values $start = 'Dec 1 2003 4 00:00 AM'; $end = 'Jan 2 2004 5 00:00 AM'; ($s_seconds, $s_year) = parse($start); ($e_seconds, $e_year) = parse($end); if ($s_seconds < $e_seconds) { $elapsed = $e_seconds - $s_seconds; } else { # # we must have rolled over to a new year so... # Grab the remaining seconds in the old year + the seconds in the new year # $elapsed = $e_seconds + ( $s_year - $s_seconds ); } $days = (split(/\./, $elapsed / 86400))[0]; $rem = $elapsed - (86400 * $days); $hours = (split(/\./, $rem / 3600))[0]; $rem -= 3600 * $hours; $mins = (split(/\./, $rem / 60))[0]; $seconds = $rem - ($mins * 60); print "Total time was: $days Days $hours Hrs $mins Mins $seconds Secs\n"; sub parse { my($line) = shift; my($mth,$day,$year,$hour,$tosplit,$arg) = split(/\s+/, $line); my($min, $sec) = split(/:/, $tosplit); # Add 12 if we are in the PM if ($arg =~ /PM/) { $hour += 12; # Set hour to 0 if its 12 AM } elsif ($hour == 12) { $hour = 0; } my($base, $total) = this_year($mth, $year); # beginning of the month + base == # of secs since beginning of year my($return) = $base + $sec + ($min * 60) + ($hour * 3600) + ($day * 86400); return($return, $total); } sub this_year { my($mth,$year,$thirty,$thirtyo,$tofind,$base,$total, %months); ($mth, $year) = @_; # number of seconds in a month with thirty days and thirty one days $thirty = "2592000"; $thirtyo = "2678400"; %months = ( Jan => [1, $thirtyo ], Feb => [2, '2419200'], Mar => [3, $thirtyo], Apr => [4, $thirty ], May => [5, $thirtyo ], Jun => [6, $thirty], Jul => [7, $thirtyo ], Aug => [8, $thirtyo ], Sep => [9, $thirty], Oct => [10, $thirtyo], Nov => [11, $thirty ], Dec => [12, $thirtyo] ); # Stupid calendar system :P # Man its way to late to be computing leap years.. stupid stupid system if (($year % 4) == 0) { $months{Feb}->[1] += '86400'; if ( ($year % 100) == 0 && ($year % 400) != 0 ) { $months{Feb}->[1] -= '86400'; } } $tofind = $months{$mth}->[0]; for ( sort { $months{$a}->[0] <=> $months{$b}->[0] } keys %months ) { $base += $months{$_}->[1] if ($tofind >= $months{$_}->[0]); $total += $months{$_}->[1]; } return($base,$total); }