Given two dates. The task is to find the number of days between the given dates.
Input : date1 = "17-09-2018" date2 = "31-09-2018" Output: Difference between two dates: 14 days Input : date1 = "2-05-2017" date2 = "25-12-2017" Output: Difference between two dates: 237 Days
Note: The dates can be taken in any format. In the above example, the date is taken in dd-mm-yyyy format.
Method 1: In this method, first take two dates and get their differences. Below is the implementation of this method.
Difference between two dates: 14 Days
Method 2 Using date_diff() Function: The date_diff() function is an inbuilt function in PHP which is used to calculate the difference between two dates. This function returns a DateInterval object on the success and returns FALSE on failure.
Difference between two dates: +8 days
- PHP | Number of week days between two dates
- Calculating total number of Hours, Days, Minutes and Seconds between two dates in Golang
- Return all dates between two dates in an array in PHP
- How to add days to $Date in PHP?
- Comparing two dates in PHP
- Compare Dates in Java
- How to calculate the difference between two dates in PHP?
- How to get highcharts dates in the x-axis ?
- Sort an array of dates in PHP
- Program to find the sum of the series (1/a + 2/a^2 + 3/a^3 + ... + n/a^n)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet