start time and end time in a database table using php and I am calculating the difference between the start time and end time to get the total duration total of a task.
I am using the following method:
foreach ($task->timers as $time ) {
$start_date = new DateTime($time->date.' '.$time->start_time);
$end_date = new DateTime($time->date.' '.$time->end_time);
$times[] = date_diff($end_date, $start_date);
}
I then loop through the array above as follows;
foreach ($times as $timer) {
$minutes = strlen($timer->i);
if($minutes == 1) {
$minutes = '0'.$timer->i;
} else {
$minutes = $timer->i;
}
$o[] = $timer->h.':'.$minutes.':'.$timer->s;
}
I then get an array as follows;
array(2) { [0]=> string(7) "0:54:17" [1]=> string(7) "0:01:26" }
Now I want to add those two values together to get the total duration and I'm attempting to do this as follows;
$totalTime = array_sum($o);
however this comes back as :
int(0);
Any ideas how I can calculate the total duration of two durations??