get time difference between two times in php code example
Example 1: difference between two timestamps php
$datetime1 = new DateTime('2016-11-30 03:55:06');
$datetime2 = new DateTime('2016-11-30 11:55:06');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%Y years %m months %d days %H hours %i minutes %s seconds');
Example 2: calculate time difference php
$time1 = new DateTime('09:00:59');
$time2 = new DateTime('09:01:00');
$interval = $time1->diff($time2);
echo $interval->format('%s second(s)');
Result: 1 second(s)