Back to Practice
#0147

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 is common in retention, subscriptions, experiment windows, and time-based feature engineering.

Function Signature

def days_between(a, b):

Examples

Example 1
Input"2026-01-01", "2026-01-10"
Output9

The difference from Jan 1 to Jan 10 is 9 full days.

Constraints

  • Return the exact requested value.
  • Handle empty or small inputs when the prompt allows them.
  • Keep the code readable and deterministic.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input"2026-01-01", "2026-01-10"
Expected9

The difference from Jan 1 to Jan 10 is 9 full days.

Hidden Test Categories
empty or smallest inputduplicates or repeated valueslarger realistic input