Probably the best way to do this is to deal with the time in seconds -- the UNIX standard of seconds since the UNIX Epoch. If you can get away with storing your time that way, it's probably a lot easier to deal with.
Using functions like time and localtime, you can get the current time in seconds and change it over to a useful format. Using the POSIX module, you can easily format the time. I would suggest running SuperSearch for additional information - the time issue comes up a lot.
An example...
#!/usr/bin/perl -w use strict; use POSIX qw(strftime); my $now = time(); #Gets current time # Subtract 3 hours, 15 minutes #(seconds/per minute * minutes/per hour * 3) = 3 hours # plus # (seconds/per minute * 15) my $earlier = $now - ((60 * 60 * 3) + (60 * 15)); # Format the times using POSIX module $now = strftime "%H:%M", localtime($now); $earlier = strftime "%H:%M", localtime($earlier); print "The current time is $now\nThe earlier time is $earlier\n";
=Output The current time is 15:40 The earlier time is 12:25

If you have to store your time in the HH:MM format, just follow Masem's excellent advice...
Rich36


There's more than one way to screw it up...


In reply to Re: adding time variables together by Rich36
in thread adding time variables together by scubaelmo

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.