Any procedural way should be avoided.
Use OOP method for date time difference:
$datetime1 = new DateTime('2016-11-30 03:55:06'); // start time
$datetime2 = new DateTime('2016-11-30 11:55:06'); // end time
$interval = $datetime1->diff($datetime2);
echo $interval
->format('%Y years %m months %d days %H hours %i minutes %s seconds');
// 00 years 0 months 0 days 08 hours 0 minutes 0 seconds
You can setup difference format as per your needs.
%Y - use for difference in year
%m - use for difference in months
%d - use for difference in days
%H - use for difference in hours
%i - use for difference in minutes
%s - use for difference in seconds
You can remove any of the above values as per your need. For example, if you only are interested in hour difference, and you know that difference can't be more than 24 hours, then use only %H
.
If you want to have total difference in seconds, then you can use:
echo $difference_in_seconds
= strtotime('2016-11-30 11:55:06') - strtotime('2016-11-30 03:55:06');
// 28800
Depends upon your need and the final format in which you want to have time difference.
For reference check: https://www.php.net/manual/en/datetime.diff.php