in reply to Difference in times (in minutes)
But if these are really local times, you are going to have trouble over dst boundaries (and some numbers will be ambiguous).$end_time = shift || "16:54:28"; $start_time = shift || "16:54:23"; if (($end_time =~ /(\d+)/)[0] < ($start_time =~ /(\d+)/)[0] || ($end_time =~ /(\d+)/)[0] == ($start_time =~ /(\d+)/)[0] && (($end_time =~ /(\d+)/g)[1] < ($start_time =~ /(\d+)/g)[1] || ($end_time =~ /(\d+)/g)[1] == ($start_time =~ /(\d+)/g)[1] && ($end_time =~ /(\d+)/g)[2] < ($start_time =~ /(\d+)/g)[2])) { $end_time =~ s/(\d+)/24+$1/e; } use List::Util "sum"; $mindiff = sum(map( 60**(2-$_)*(($end_time =~ /(\d+)/g)[$_]-($start_ti +me =~ /(\d+)/g)[$_]), 0..2 ))/60; print $mindiff, "minutes (", $mindiff*60, " seconds)\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Difference in times (in minutes)
by blackadder (Hermit) on Dec 14, 2004 at 15:58 UTC |