0
I have the result in decimal or integer of hours:
Utilizador 1 = 71.5 horas Utilizador 2 = 137 horas
I wanted to convert inside php to hours, as an example:
Utilizador 1 = 71:30 Utilizador 2 = 137:00
I’m using this code on while
to arrive at hours in decimal or integer:
$Total = 0;
while ($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$teste = $rows_cursos['Horas Consumidas'];
$tempo = explode(":", $teste);
$tempototal = $tempo[0]*60 + $tempo[1];
$Total = $Total + $tempototal;
}
$Total = $Total/60;
If
$minutos
is less than 60,$horas
will always be 0, then that operation,floor($minutos / 60)
, would be unnecessary.– Woss
@Andersoncarloswoss truth man !
– rbz
But how do I apply with the code I have this function?
– Bruno
@Beginner I just posted
– rbz
Could even make a
if
for the calculation of hours if the minutes are less than 60, but I do not see need, because if will arrive condition and execution (in the larger case) would be 2 steps against 1, and if minutes are less, it will be a check step or already thefloor
straightforward.– rbz
I put it like this, but it doesn’t work:
$tabela4 .= '<strong>Total de Horas Consumidas:</strong> ' . $Horas = convertHoras($Horas) . ' horas';
– Bruno
You are declaring the variable
$Horas
this way. The correct is' . echo convertHoras($Horas) . '
– rbz