Carbon Difference in Time between two Dates in hh:mm:ss format

I ended up grabbing the total seconds difference using Carbon:

$totalDuration = $finishTime->diffInSeconds($startTime);
// 21

Then used gmdate:

gmdate('H:i:s', $totalDuration);
// 00:00:21

If anyone has a better way I'd be interested. Otherwise this works.


$finishTime->diff($startTime)->format('%H:%I:%S');
// 00:00:21

$start  = new Carbon('2018-10-04 15:00:03');
$end    = new Carbon('2018-10-05 17:00:09');

You may use

$start->diff($end)->format('%H:%I:%S');

which gives the difference modulo 24h

02:00:06

If you want to have the difference with more than 24h, you may use :

$start->diffInHours($end) . ':' . $start->diff($end)->format('%I:%S');

which gives :

26:00:06