in reply to Subtracting and Comparing Two Dates
It may not be elegant, and could defintely benefit from some cleaner formatting like use of constants, but it gets the point acrossuse POSIX qw/difftime mktime/; my $now = time(); my @then = ($ARGV[0] =~ /^(\d{4})(\d{2})(\d{2})/); my $then = mktime(0,0,0,$then[2],$then[1]-1,$then[0]-1900); my $diff = difftime($now,$then); printf("%d days", int($diff/86400) ); printf(", %d hours", int( $diff%86400)/3600 ); printf(", %d minutes ", int( ($diff%86400)%3600 )/60 ); printf(", %d seconds \n", ( ($diff%86400)%3600 )%60 );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Subtracting and Comparing Two Dates
by ikegami (Patriarch) on Jan 09, 2007 at 03:01 UTC |