0
I’m making a calculation between dates and times but when displaying the value with printf
the result is one and with echo
is different.
With this calculation the value is displayed correctly:
$Entrada = strtotime( '2010-05-26 08:00' );
$Saida = strtotime( '2010-05-26 11:15' );
$Diferenca = $Saida - $Entrada;
$hora = $Diferenca/3600;
$min = $Diferenca/60%60;
printf( '%d:%d', $hora, $min );
The result is: 3:15
And thus the result is added a value at the end:
$Entrada = strtotime( '2010-05-26 08:00' );
$Saida = strtotime( '2010-05-26 11:15' );
$Diferenca = $Saida - $Entrada;
$hora = $Diferenca/3600;
$min = $Diferenca/60%60;
$Resultado = printf( '%d:%d', $hora, $min );
echo $Resultado;
The result is: 3:154
Look at the PHP Sandbox
To save the value in a variable, you need to use sprintf. The printf is only for the formatted view.
– lvr7
Hello @lvr7, for you see, did not know this, thanks for the tip.
– adventistapr