I need to convert two values from minutes to hours using PHP.
valor1 = 278 min
valor2 = 1161 min
I need to convert two values from minutes to hours using PHP.
valor1 = 278 min
valor2 = 1161 min
$minutos_totais = 278;
$horas = floor($minutos_totais / 60);
$minutos = $minutos_totais % 60;
php > $minutos_totais = 1439;
php > echo floor($minutos_totais / 60);
23
php > echo $minutos_totais % 60;
59
By the statement of the question, the intention is to convert the number of minutes into hours, and not return hours and minutes .
The correct thing is to only divide the minutes by 60, returning the value in hours with decimals (if the value is not a multiple of 60):
<?php
$valor1 = 278;
$valor2 = 1161;
// arredondando para 2 casas decimais
$valor1 = round($valor1 / 60, 2); // retorna 4.63
$valor2 = round($valor2 / 60, 2); // retorna 19.35
?>
That is, 278 minutes equals 4.63 hours , and 1161 minutes sa 19.35 hours >.
If you do not want the decimals (the rest that did not complete 1 hour):
<?php
$valor1 = 278;
$valor2 = 1161;
// arredondando para 2 casas decimais
$valor1 = floor($valor1 / 60); // retorna 4
$valor2 = floor($valor2 / 60); // retorna 19
?>