echo sum_the_time('01:45:22', '17:27:03');
function sum_the_time($time1, $time2) {
$times = array($time1, $time2);
$seconds = 0;
foreach ($times as $time)
{
list($hour,$minute,$second) = explode(':', $time);
$seconds += $hour*3600;
$seconds += $minute*60;
$seconds += $second;
}
$hours = floor($seconds/3600);
$seconds -= $hours*3600;
$minutes = floor($seconds/60);
$seconds -= $minutes*60;
// return "{$hours}:{$minutes}:{$seconds}";
return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
not working ..
ReplyDeleteSorry for late reply.. it will work if we add "}" for the function ending. I am sorry i missed out, please check below
ReplyDeletefunction sum_the_time($time1, $time2) {
$times = array($time1, $time2);
$seconds = 0;
foreach ($times as $time)
{
list($hour,$minute,$second) = explode(':', $time);
$seconds += $hour*3600;
$seconds += $minute*60;
$seconds += $second;
}
$hours = floor($seconds/3600);
$seconds -= $hours*3600;
$minutes = floor($seconds/60);
$seconds -= $minutes*60;
return "{$hours}:{$minutes}:{$seconds}";
//return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
}
echo sum_the_time('01:45:22', '17:27:03');
It did not give output when put it or call this function inside while loop. can u help me in this. I need to put this function in a while loop.
ReplyDeleteIt is done.
ReplyDeleteCan you please show me how you use this function in a while loop?
DeleteHelp would be very much appreciated.. Thank You :)
Have you got this?
Delete