I'm trying to get the difference between two datetimes and return it as a datetime
. I've found examples using diff
but I can't seem to get it right.
$timein = date("Y-m-d H:i:s");
$timeout = date("Y-m-d 20:00:00");
$totaltime = $timein->diff($timeout);
However $totaltime
logs 0000-00-00 00:00:00
to my DB. Is this because I'm not formatting my totaltime variable?
I'm not sure what format you're looking for in your difference but here's how to do it using DateTime