Check it out:
if use $date2
as 24:00
$date1 = new DateTime('02:40');
$date2 = new DateTime('24:00');
$finaldate = $date2->diff($date1);
echo $finaldate->format('%h:%i'); // 21:20
But if use $date2
as 00:00
$date1 = new DateTime('02:40');
$date2 = new DateTime('00:00');
$finaldate = $date2->diff($date1);
echo $finaldate->format('%h:%i'); //02:40
1
solved Time Subtract in PHP