Back to Practice
#0073
Days Between Dates
EasyPython15 min10 XP
Problem
Given two strings in YYYY-MM-DD format, return the absolute number of days between them.
Why This Matters
Date arithmetic appears in retention, subscriptions, SLAs, time-series features, and reporting.
Function Signature
def days_between(start, end):
Examples
Example 1
Input"2026-01-01", "2026-01-10"
Output9
The difference between Jan 1 and Jan 10 is nine full days.
Constraints
- Inputs are valid ISO date strings.
- Return an absolute difference.
- Use datetime/date parsing, not manual month arithmetic.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 3 hidden categories
Forward dates
Input"2026-01-01", "2026-01-10"
Expected9
Subtracting date objects handles calendar details.
Reverse dates
Input"2026-01-10", "2026-01-01"
Expected9
The function returns absolute difference.
Hidden Test Categories
same dateleap year datemonth boundary