2
I am needing to calculate an average not only between an initial date and a final date, but on all dates present in a matrix to obtain an average result in days, hours, minutes and seconds of how much X in X time such an event is recorded.
I have already developed a basis for this calculation but it does not seem to be correct, because let’s look at the example:
$dates = ['2015-05-10 12:00:00', '2015-05-11 12:00:00', '2015-05-12 12:00:00'];
$dates = array_map('strtotime', $dates);
for($count = count($dates), $result = 0, $i = 1; $i < $count; $i++)
{
$result += $dates[$i-1] - $dates[$i];
}
$seconds = floor($result / $count);
$DTF = new DateTime("@0");
$DTT = new DateTime("@$seconds");
echo $DTF->diff($DTT)->format('%a dias, %h horas, %i minutos e %s segundos');
In the array, the difference between these 3 dates is exactly 24 hours, but the result since the calculation is: 0 dias, 16 horas, 0 minutos e 0 segundos
, what could be wrong?
The expected result is?
– rray