Get time difference in minutes in PHP
Question:
How to get time difference in minutes in PHP? Answer:
$start = new DateTime($startTime);
$end = new DateTime($endTime);
$diff = $end->diff($start);
$days = $diff->format('%a');
$hours = $diff->format('%h');
$minutes = $diff->format('%i');
$diffInMinutes = $days * 24 *60 + $hours * 60 + $minutes;
Description:
To get the difference between 2 times in minutes or any other measure you can create a DateTime
object for both times and use the diff
method. The result is a DateInterval
object that can return the difference in formats as defined in the formating table.
Reference:
DateInterval format reference
Share "How to get time difference in minutes in PHP?"
Related snippets:
- Add minutes to date time in PHP
- Add days to date in PHP
- Get same day in the next week in PHP
- Get time difference in minutes in PHP
- Convert date to timestamp in PHP
- Convert timestamp to DateTime in PHP
- Get the last day of a month from date in PHP
- Get the number of days between two dates in PHP
- Get yesterday's date in PHP
- Get tomorrow's date in PHP
- Get current time in PHP
- Get actual date in PHP
Tags:
time difference, date difference, difference in minutes Technical term:
Get time difference in minutes in PHP