Given two strings str1 and str2 which represent two dates, the task is to count the number of days between given two dates. Given that dates given are beyond 1971.
Input: str1 = “2020-01-29”, str2 = “2020-01-30”
The number of days between 29th January and 30th January is 1.
Input: str1 = “1971-06-29”, str2 = “2019-06-23”
Approach: The idea is to convert both the dates into its respective seconds. Since there are 86, 400 seconds in a day, the number of days between both the days can be found out by dividing the difference of seconds with 86, 400.
Below is the implementation of the above approach:
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.
- Find number of days between two given dates
- Program to convert given number of days in terms of Years, Weeks and Days
- Total number of days taken to complete the task if after certain days one person leaves
- Print all palindrome dates between the given years
- Program to calculate the number of odd days in given number of years
- Find temperature of missing days using given sum and average
- Date after adding given number of days to the given date
- C program to print number of days in a month
- Maximize number of days for which P chocolates can be distributed consecutively to N people
- Finding LCM of more than two (or array) numbers without using GCD
- Converting seconds into days, hours, minutes and seconds
- Count of days remaining for the next day with higher temperature
- Find the day of the week after K days from the given day
- Finding number of digits in n'th Fibonacci number
- Finding Median of unsorted Array in linear time using C++ STL
- Finding Integreand using Weedle's Rule
- Program for finding the Integral of a given function using Boole's Rule
- Finding sum of digits of a number until sum becomes single digit
- Finding n-th number made of prime digits (2, 3, 5 and 7) only
- Finding power of prime number p in 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 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.