Puoi calcolarlo usando la funzione timeDiff:
times = array();
foreach ($result as $row){
// convert to unix timestamps
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
// perform subtraction to get the difference (in seconds) between times
$timeDiff=$lastTime-$firstTime;
$times[] = $timeDiff;
echo(secondsToTime($timeDiff));
# 18 days, 23 hours, 41 minutes and 7 seconds
}
echo(secondsToTime(array_sum($times)));
#total of all times