1274. Number of Days Between Two Dates
My accepted Python solution to LeetCode problem 1274, Number of Days Between Two Dates, running in 2ms.
- Difficulty: Easy
- Python
- Runtime 2ms
- Memory 17.7MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 2ms, memory 17.7MB, accepted 2025-12-30.
class Solution:
def daysBetweenDates(self, date1: str, date2: str) -> int:
from datetime import datetime
d1 = datetime.strptime(date1, "%Y-%m-%d")
d2 = datetime.strptime(date2, "%Y-%m-%d")
return abs((d2 - d1).days)