Jump to content

Time calculation problem


ramli

Recommended Posts

I want to calculate a total time using the following script:

[code]

while($r1 = mysql_fetch_array($Query1))
{

$difference = $r1['difference']; // time in format 15:15:30
$difference = microtime($difference);  // Transorm to milliseconds
$verschil = $verschil + $difference; //Add differance of every record to the total difined as $verschil

}

$seconds = floor(($verschil)); //calculate seconds of the total
$minutes = floor(($verschil / 60)); //calculate hours of the total
$hours = floor(($verschil / 60) /60);//calculate seconds of the total



[/code]

where difference is a database object in the format 00:00:00.

I dont seem to get it to work wat am i doing wrong ?

Thanx in advance....
Link to comment
https://forums.phpfreaks.com/topic/32872-time-calculation-problem/
Share on other sites

try[code]<?php
$a = array('07:43:09','11:51:51');
$total = 0;
foreach ($a as $b){
$x = explode(':',$b);
$tmp = 0;
foreach ($x as $c) {$tmp = $tmp * 60 + $c;}
$total += $tmp;
}
$out = array();
for ($i=0; $i<3; $i++){
$t = floor($total / 60);
$out[] = sprintf( "%02d", $total - $t * 60);
$total = $t;
}
echo $out = implode(':',array_reverse($out));
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.