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 mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.