任何人都可以帮我解决这个问题:可恢复的致命错误:类DateTime的对象无法转换为字符串[duplicate]

This question already has an answer here:

I have prob with the time after the subtraction to be inserted into database

$time = new DateTime('08:10:00');
$timein = new DateTime('17:05:00');
$newtime = $timein->diff($time);
$sql = "UPDATE staff_attendance SET total_working_time='$result' WHERE id='$a_id'";
</div>

You need to fetch difference and then convert to H:i:s, like this:

$hour = $newtime->format('%h');
$minute = $newtime->format('%i');
$second = $newtime->format('%s');

$year = $newtime->format('%y');
$month = $newtime->format('%m');
$day = $newtime->format('%d');

$time = $hour.':'.$minute.':'.$second; // H:i:s

https://paiza.io/projects/QKxRTpDEo6zRjooQAfdONQ?language=php