[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

No Infrastructure! No Waste of Time! There is Amazon EMR!

Haskell Curry ( and Uncurry)

The Cloud Native Architect

Tutorial Fuzzy Logic Mamdani for Arduino

Tutorial Fuzzy Logic Mamdani for Arduino

Lok Sewa Online Test for Computer Operator Fundamentals Set 39

Really suggest protect.

How to Deploy The Laravel APP on AWS EC2

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

Sorting Algorithms Explained Using Python: Heap Sort

Glass Cube and Dots

[LeetCode]#2114. Maximum Number of Words Found in Sentences

LeetCode #1332 | Remove Palindromic Subsequences

LeetCode Patterns Adventure 32 — Backspace String Compare