- Instant help with your Php coding problems

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.

Share "How to get time difference in minutes in PHP?"