I am saving the time in the database with a field of type time
. I'm going through an array of data and I want to be able to add them.
I have the following method:
<?php sumaHoras = 0; ?>
<?php while ($row = mysqli_fetch_assoc($result)) { ?>
$value_horario = $row['total'];
$parts = explode(':', $value_horario);
$resultado = ($parts[0] + ($parts[1]/6) / 10 . PHP_EOL);
$sumaHoras = $sumaHoras + $resultado;
} ?>
<?php echo $sumaHoras; ?>
If in my Array $row['total']
comes 3 hours, the sum of those 00:30:00
+ 04:30:00
+ 01:00:00
results in 1.50
. I should give 7:00
or 07:00:00
.
I've been looking at some codes but none of them has worked for me.