I have these PHP codes where I wanted to calculate the time difference between 2 given time.
// This is 2:00 am o'clock
$time1 = 02:00;
// This is 9 pm o'clock
$time2 = 21:00;
I want to calculated backwards time difference between 2am – 9pm, So the time difference should be 5hrs.
I tried the following but did not get the correct result:
$diff = date('H:i:s a', strtotime($time1)) - date('H:i:s a', strtotime($time2));
echo $diff;
2
Answers
Online Demo: https://onecompiler.com/php/42kbtdbzt