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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.