Background
I have a simple question and i am sure this problem has been asked before. I have a bunch of times (in 24 hunder hour format e.g., 0930, 2300) that have a toTime and fromTime. All i have to do is take the time passed between each toTime and fromTime and add these resulting time(s) to form a grand total.

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

Giving us a total of Total Time in Hrs and Mins = 4 hours and 49 mins
This is what i am trying to do.

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.


In reply to calculate hours of day by data67

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.