[LeetCode]#1360. Number of Days Between Two Dates

Input: date1 = "2019-06-29", date2 = "2019-06-30"
Output: 1
Input: date1 = "2020-01-15", date2 = "2019-12-31"
Output: 15
  • The given dates are valid dates between the years 1971 and 2100.
import datetime
class Solution:
def daysBetweenDates(self, date1, date2):
day1 = datetime.datetime(int(date1[0:4]), int(date1[5:7]) , int(date1[8:10]))
day2 = datetime.datetime(int(date2[0:4]), int(date2[5:7]) , int(date2[8:10]))


ans=abs((day1 - day2).days)
return ans

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Version Control: What it is (Part 1)

On-demand Resources

The Little Bird IV

S.O.L.I.D. Principles: Simplified Explanation & Example

Microsoft Defender for endpoint server licensing

Microsoft Defender for endpoint server licensing

How many alarm do you have on your iPhone clock?

Mysql Select Empty JSON Array

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

How to implement a Queue class using deque. PYTHON data structures and algorithm.

[LeetCode]#2057. Smallest Index With Equal Value

Leetcode — Capacity To Ship Packages Within D Days

Remove nth node from end of list Leetcode Python