Max
Max

Reputation: 33

Formatting diff from datetime object doesn't count years/months/days

I'm trying to format difference between two datetime objects so that it returns HH:MM:SS. In my case I can't seem to figure out how to get years/months/days to be added to hours.

//These are retrieved formatted as datetime from the database
start_time = "2016-08-12 15:58:42"
stop_time = "2016-08-14 17:00:53"

$start_time = new DateTime($item['start_time']);
$stop_time = new DateTime($item['stop_time']);
$item['total_read_time'] = $start_time->diff($stop_time)->format('%H:%I:%S');

return $item;

This returns 01:02:11 which is not correct. I want it to count years, months and days as well, so 49:02:11 would be correct.

Is there a clean way to do this correctly?

Upvotes: 0

Views: 167

Answers (0)

Related Questions