Good day Monks!

So I am using this code that works perfectly on a website.

On the website it displays 0d 1h 17m 43s, days hours minutes and seconds for how long that process ran for.

But I used a similiar code to print "Duration : 0d 0h 5m 0s" every 5 minutes to show how long the process has been running so they know when they want to stop.

For some reason, once it hits 1 hour, it doesn't print "Duration : 0d 1h 0m 0s", instead it prints "Duration : 0d 0h 0m 0s".

The .cgi and .pl uses the same code to convert the time so I have no idea why it doesn't show the hour..

while (1) { my $days = int($runtime / 86400); $runtime -= ($days * 86400); my $hours = int($runtime / 3600); $runtime -= ($hours * 3600); my $minutes = int($runtime / 60); my $seconds = $runtime % 60; $days = $days .'d '; $hours = $hours .'h '; $minutes = $minutes .'m '; $runtime2 = $runtime; $runtime2 = $days . $hours . $minutes . $seconds . 's'; if (time()>=$nextruntime){ $nextruntime=time()+300; $runtime += 300; print "Duration: $runtime2\n"; }

Code used for the .cgi

my $epochrun = $epochend - $epochstart; my $days = int($epochrun / 86400); $epochrun -= ($days * 86400); my $hours = int($epochrun / 3600); $epochrun -= ($hours * 3600); my $minutes = int($epochrun / 60); my $seconds = $epochrun % 60; $days = $days .'d '; $hours = $hours .'h '; $minutes = $minutes .'m '; $epochrun = $days . $hours . $minutes . $seconds . 's';

Thanks in advance!

This just finished printing...

Starting iostat-10-test-2014_06_30-09:57:35_EDT Starting vmstat-10-test-2014_06_30-09:57:35_EDT Duration: 0d 0h 0m 0s Starting mpstat-10-test-2014_06_30-09:57:35_EDT Duration: 0d 0h 5m 0s Duration: 0d 0h 10m 0s Duration: 0d 0h 15m 0s Duration: 0d 0h 20m 0s Duration: 0d 0h 25m 0s Duration: 0d 0h 30m 0s Duration: 0d 0h 35m 0s Duration: 0d 0h 40m 0s Duration: 0d 0h 45m 0s Duration: 0d 0h 50m 0s Duration: 0d 0h 55m 0s Duration: 0d 0h 0m 0s

In reply to Timestamp doesn't work well by Jabox

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.