I'm calculating in PHP the difference between datetimes
(start, end), coming from a POST
, need to fill a campo(time)
in format(H:i:s)
via INSERT
in MYSQL
.
I get the result of the difference, but I can not use it because when I do the 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 an error of string
same, how do I do the conversion? Is there any other way to do this in 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 ever-present partnership
P.S .: If you already have this question clarified in another post inform me, but I checked first and I'm beating myself a lot.