2
I’m calculating in PHP the difference between two datetimes
(beginning, end), from a POST
, need to fill out a campo(time)
in the format(H:i:s)
via INSERT
in the MYSQL
.
I get the result of the difference, but I can’t use it because by insert
I get an error saying that the difference field is not converted to string
:
Error: "(Object of class Dateinterval could not be converted to string)".
If it is the error of string
same, how do I perform the conversion? Is there any other way to do this in the PHP
?
$inicio = new DateTime($data_inicio);
$fim = new DateTime($data_fim);
$duracao = $inicio->diff($fim);
$duracao = $duracao->format('%h:%i:%s');
$sql = "INSERT into horarios VALUES ('$duracao')";
Thank you for your partnership
P.S.: In case you already have this doubt clarified in another post inform me, but I did a research first and I’m hitting myself a bit.
See if it helps Calculate time interval in hours and minutes considering different days
– Bacco
I took a look, I did not understand very well... I will review later, I would like something simple as diff, in case there is I prefer to do it via some javascript Moment library and only post the value already calculated.
– Cleverson