It would help immensely (to help you) if you post some sample data that you are trying to parse, and not create a HTML paragraph every one-and-a-half sentences.

By the way, there are 3600 seconds in an hour not 360, unless your comment has a typo...

... } # I could use: $stime = ($datetemp[3] * 360) + ($datetemp[4] +* 60) # <-- convert to seconds ...

And since you are repeating the algorithm to generate $stime and $etime, why not create a sub so that you do not have to repeat the same 9-12 lines.

As to your problem, cause is obvious. You are using only the the hours, minutes (and seconds); you NEED to consider the day-of-the-month, month, and year. To calculate elasped time properly, you need to, for start and end time,...

  1. extract all five (six) date/time values
  2. convert them to the appropriate lowest unit of time measurement
  3. take the difference as you are already doing


...you can either create your own algorithm (which i prefer for myself) or use module(s)...


In reply to Re: Elapsed date and time by parv
in thread Elapsed date and time by dbrock

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.