This is one way of doing it, but it is a bit more lengthy than is needed. In the next sample I show you how you can do that a bit easier. But both methods start at the high end: begin to calculate the hours and then go downwards, as I showed you in my previous post.
Method 1 calculates every value in a separate variable, and is outputted when all values have been calculated.
Method 2 is a lot shorter, it displays the calculation direct to the screen. And when you want it shorter still, you can use the constant values directly in the method 2, but that makes it harder to read.
[php]<?php
// ------------------------------------------------
// Calculate HH:MM:SS:TH from time in milliseconds
// ------------------------------------------------
// setup the test time 13:44:21:33
$mytime = (1000 * 60 * 60 * 13) + (1000 * 60 * 44) + (1000 * 21) + 333; initialize the constants
$msec_hh = 1000 * 60 * 60; // millisecs per hour
$msec_mm = 1000 * 60; // millisecs per minute
$msec_ss = 1000; // millisecs per second
//----------------------------
// Method 1 indirect
// ---------------------------
// calculate HH:MM:SS:TH
$hh = $mytime / $msec_hh; // divide by millisecs per hour => hrs
$r = $mytime % $msec_hh;
$mm = $r / $msec_mm; // divide rest by millisecs per minute => mins
$r = $r % $msec_mm;
$ss = $r / $msec_ss; // divide rest by millisecs per second => secs
$r = $r % $msec_ss;
echo sprintf("Duration is %02s:%02s:%02s:%02s", (int)$hh, (int)$mm, (int)$ss, (int)$r);
//----------------------------
//method 2 direct
//----------------------------
echo sprintf("<br>Duration is %02s:%02s:%02s:%02s",
(int)($mytime / $msec_hh),
(int)(($mytime % $msec_hh) / $msec_mm),
(int)((($mytime % $msec_hh) % $msec_mm) / $msec_ss),
(int)((($mytime % $msec_hh) % $msec_mm) % $msec_ss) );
?>
[/php]
Ronald :cool: