ramli Posted January 4, 2007 Share Posted January 4, 2007 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.... Quote Link to comment https://forums.phpfreaks.com/topic/32872-time-calculation-problem/ Share on other sites More sharing options...
ShogunWarrior Posted January 4, 2007 Share Posted January 4, 2007 Microtime's only argument is whether or not to return a decimal value, you can't shove your 00:00:00 time into it. Quote Link to comment https://forums.phpfreaks.com/topic/32872-time-calculation-problem/#findComment-153122 Share on other sites More sharing options...
ramli Posted January 4, 2007 Author Share Posted January 4, 2007 clould you help me with a solution pleace ? Quote Link to comment https://forums.phpfreaks.com/topic/32872-time-calculation-problem/#findComment-153127 Share on other sites More sharing options...
sasa Posted January 4, 2007 Share Posted January 4, 2007 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] Quote Link to comment https://forums.phpfreaks.com/topic/32872-time-calculation-problem/#findComment-153171 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.