I want to get time difference in HH:MM:SS format below is the code
if time diff in seconds it should display l like 00:00:35 In minutes :00:30:35 In Hrs :01:30:35
use
$hours = $interval->format('%H');
$minutes = $interval->format('%I');
$seconds = $interval->format('%S');
and concat both three for one variable
or use $interval->format('%H:%I:%S')
for single output
//output 00:30:35
You can use strtotime() for time calculation. Here is an example:
$time1 = strtotime('10:55:59');<br>
$time2 = strtotime('10:56:00');<br>
$diff = $time2 - $time1;<br>
echo 'Time 1: '.date('H:i:s', $time1).'\n';<br>
echo 'Time 2: '.date('H:i:s', $time2).'\n';
if($diff){<br>
echo 'Diff: '.date('H:i:s', $diff);<br>
}else{<br>
echo 'No Diff.';<br>
}<br>
Output:
Time 1: 09:00:59<br>
Time 2: 09:01:00<br>
Diff: 00:00:01