Ctrl K

Days Between Two Dates

Easy
You are given two dates first and second in the YYYY-MM-DD format. Return the number of days between them. The dates may come in either order; the answer is never negative. Mind the leap years: a year is a leap year if it is divisible by 4, except years divisible by 100 but not by 400.
Example 1
first="2024-02-27", second="2024-03-02" → 4

2024 is a leap year, so February has 29 days: from Feb 27 to Mar 2 is four days.

Example 2
first="2031-01-10", second="2030-12-25" → 16

The order of the dates does not matter: from Dec 25 to Jan 10 is 16 days.

Example 3
first="1999-07-04", second="1999-07-04" → 0
Constraints
  • Both dates exist in the calendar
  • Years are between 1971 and 2100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasySum of Binary Strings EasySpreadsheet Column Label EasySpreadsheet Column Index EasyCounting Off by Threes and Fives Easy
loading Python…
Input
first="2024-02-27", second="2024-03-02"
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 141 tests on the server, hidden ones included.