0

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 formated 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 wich is not correct. I want it to count years, months and days aswell, so 49:02:11 would be correct.

Is there a clean way to do this correctly?

Max
  • 33
  • 5
  • Possible duplicate of [How to get time difference in minutes in PHP](http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php) – Alok Patel Aug 26 '16 at 11:36
  • you want 49 years, 2 months, 11 days as output? –  Aug 26 '16 at 11:48
  • if you want years, months, days as output try this, $item = $start_time->diff($stop_time)->format('%y:%m:%d'); –  Aug 26 '16 at 11:57
  • To make things clear, I want to keep the HH:MM:SS format were hours is limitless. – Max Aug 26 '16 at 12:55

0 Answers0