data67 has asked for the wisdom of the Perl Monks concerning the following question:
Example
add the following times:
toTime -- fromTime 0715 0945 = 2 hrs and 30 mins 1107 1256 = 1 hr and 49 mins 0845 0915 = 0 hr and 30 mins
Here is what i have for now, one of the main problems i face is how to convert a number of minutes to hr/min format.
#!perl use Data::Dumper; print "this is a test\n"; my %HoH = ( "toTime" => "1220", "fromTime" => "0930" ); #print Dumper (\%HoH); my $fromTime = $HoH{"fromTime"}; my $toTime = $HoH{"toTime"}; print "$fromTime\n"; my ($fromTimeHr, $fromTimeMin, $toTimeHr, $toTimeMin); if ($fromTime =~ /(\d{2})(\d{2})/) { print "FOMRTIME Hr = $1 / Min = $2\n"; $fromTimeHr = $1; $fromTimeMin = $2; } if ($toTime =~ /(\d{2})(\d{2})/) { print "TOTIME Hr = $1 / Min = $2\n"; $toTimeHr = $1; $toTimeMin = $2; } # Now convert Hrs to Mins and and all Mins my $totalFromTime = ($fromTimeHr * 60) + $fromTimeMin; my $totalToTime = ($toTimeHr * 60) + $toTimeMin; print "Total From Time Mins = $totalFromTime\n"; print "Total To Time Mins = $totalToTime\n";
As always, thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: calculate hours of day
by Zaxo (Archbishop) on Sep 07, 2003 at 21:41 UTC | |
by Jeppe (Monk) on Sep 08, 2003 at 10:24 UTC | |
|
Re: calculate hours of day
by Not_a_Number (Prior) on Sep 07, 2003 at 22:33 UTC | |
|
Re: calculate hours of day
by PodMaster (Abbot) on Sep 08, 2003 at 01:07 UTC | |
|
Re: calculate hours of day
by CombatSquirrel (Hermit) on Sep 07, 2003 at 21:43 UTC | |
|
Re: calculate hours of day
by gwadej (Chaplain) on Sep 07, 2003 at 21:49 UTC |