To get the number of days between two dates, we can calculate the number of days from the beginning 0/0/0000 to the first date and the second date and compute their difference.
Input: 2020-04-27 23:35:00, 2018-5-12 12:43:23 Output: 716 days, 10 hours, 51 minutes, 37 seconds Input: 2014-02-25 05:50:20, 2003-12-13 21:42:12 Output: 3726 days, 8 hours, 8 minutes, 8 seconds
To calculate the time difference, we can calculate hours2-hours1, minutes2-minutes1, seconds2-seconds1, and perform some operations (shown in the code from line 65 to line 80) to avoid negative values.
716 days, 10 hours, 51 minutes, 37 seconds
- Program to find the number of days between two dates in PHP
- Return all dates between two dates in an array in PHP
- time.Hours() Function in Golang With Examples
- time.Seconds() Function in Golang With Examples
- time.Minutes() Function in Golang With Examples
- How to add 24 hours to a unix timestamp in php?
- How to calculate the difference between two dates in PHP?
- How to get the current date and time in seconds?
- How to reload page after specific seconds in jQuery ?
- Comparing two dates in PHP
- Compare Dates in Java
- How to get highcharts dates in the x-axis ?
- How to add days to $Date in PHP?
- Difference between var keyword and short declaration operator in Golang
- Difference Between Golang and Ruby
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.