How do I work out the average time from an array of times.
I have an array that looks like this :
('17:29:53','16:00:32')
And I wish to achieve the result 16:45:12
using PHP.
date('H:i:s', array_sum(array_map('strtotime', $array)) / count($array))
Untested solution typed on my phone, should work though.
$times = array('17:29:53','16:00:32');
$totaltime = '';
foreach($times as $time){
$timestamp = strtotime($time);
$totaltime += $timestamp;
}
$average_time = ($totaltime/count($times));
echo date('H:i:s',$average_time);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With