![]() |
VOOZH | about |
In this article, we will learn how to get time difference in minutes using PHP.
We will be using the built-in function date_diff() to get the time difference in minutes. For this, we will be needed a start date and end date to calculate their time difference in minutes using the date_diff() function.
Syntax:
date_diff($datetime1, $datetime2);Parameters: The date_diff() function accepts two parameters as mentioned above and described below.
Return Value: This function returns the difference between the first DateTime object and the second DateTime object otherwise it returns false on failure.
Example 1: The below program illustrates the date_diff() function to get the time difference in minutes.
Output:
Difference in days is: +366 days
Difference in minutes is: 527040 minutes
Example 2:
Output:
Difference in days is: +276 days
Difference in minutes is: 397440 minutes
Example 3:
Output:
Difference in hours is:7
Difference in minutes is:420 minutes
Another approach to calculate the time difference in minutes between two dates is by using the strtotime() function. This method involves converting the date strings into Unix timestamps and then calculating the difference.
Example:
Difference in minutes is: 528480 minutes