Given two dates, start_date and end_date. The task is to find the difference between two dates.
Input: start_date: 2016-06-01 22:45:00 end_date: 2018-09-21 10:44:01 Output: 2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds Input: start_date: 2015-05-12 12:37:30 end_date: 2018-04-25 12:45:31 Output: 2 years, 11 months, 19 days, 0 hours, 8 minutes, 1 seconds
Method 1: Use date_diff() Function to find the difference between two dates.
Method 2: To use date-time mathematical formula to find the difference between two dates. It returns the years, months, days, hours, minutes, seconds between two specified dates.
2 years, 3 months, 21 days, 11 hours, 59 minutes, 1 seconds
Method 3: This method is used to get the total number of days between two specified dates.
Difference between two dates: 103
- Return all dates between two dates in an array in PHP
- Comparing two dates in PHP
- Compare Dates in Java
- Sort an array of dates in PHP
- PHP | Number of week days between two dates
- Program to find the number of days between two dates in PHP
- How to calculate total time of an array in PHP ?
- How to calculate the number of words in a string using JQuery?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.