Days Between Two Dates
Medium · Dates
The datetime module has a date type. date.fromisoformat("2026-03-01") parses a YYYY-MM-DD string. Subtracting two dates gives a timedelta, and its .days attribute is the number of days. Leap years are handled for you.
Write days_between(start, end) that returns how many days lie between two YYYY-MM-DD dates. The answer is never negative, so the order of the two dates does not matter.
Next: Total of a JSON Order