View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
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[]toget 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.
- $datetime1: This is a mandatory parameter as it specifies the start/first DateTime object.
- $datetime2: This is a mandatory parameter as it specifies the end/second DateTime object.
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.
PHP
Output:
Difference in days is: +366 days Difference in minutes is: 527040 minutes
Example 2:
PHP
Output:
Difference in days is: +276 days Difference in minutes is: 397440 minutes
Example 3:
PHP
Output:
Difference in hours is:7 Difference in minutes is:420 minutes