Subtracting one date from another gives a timedelta, the length of time between them. Its .days attribute is the number of days.
The program
from datetime import date first = date.fromisoformat(input("First date (YYYY-MM-DD): ")) second = date.fromisoformat(input("Second date (YYYY-MM-DD): ")) gap = abs((second - first).days) weeks, days = divmod(gap, 7) print(f"Days between: {gap}") day_word = "day" if days == 1 else "days" print(f"That is {weeks} weeks and {days} {day_word}.")
Typed in this example: 2026-10-22, 2026-12-25. Press Run to type your own.
First date (YYYY-MM-DD): 2026-10-22 Second date (YYYY-MM-DD): 2026-12-25 Days between: 64 That is 9 weeks and 1 day.
How it works
date.fromisoformat("2026-10-22")turns text in the form year-month-day into adateobject. Text that is not a real date, such as2026-02-30, raises aValueError.second - firstis atimedelta. If the second date is earlier, the result is negative, soabs()makes the gap positive whichever order the dates are typed in.divmod(gap, 7)gives the whole weeks and the days left over in one step:divmod(64, 7)is(9, 1).day_wordavoids printing "1 days".- The count does not include the start day. From Monday to Tuesday is 1 day. If you need to count both the first and the last day, add 1.
To handle a typing mistake without a crash, put the fromisoformat() call in a try/except ValueError loop, as in the input validation loop.
Working days only
weekday() returns 0 for Monday up to 6 for Sunday. Step through the dates one day at a time and count the days that are not Saturday or Sunday:
from datetime import date, timedelta def working_days(start, end): count = 0 day = start while day < end: if day.weekday() < 5: count += 1 day += timedelta(days=1) return count start = date(2026, 10, 22) end = date(2026, 12, 25) print(f"Working days from {start} up to {end}: {working_days(start, end)}")
Working days from 2026-10-22 up to 2026-12-25: 46
The loop counts start but not end, in the same way as the subtraction above. Public holidays are different in every country, so they are not counted here. To skip them, keep a set of holiday dates and check day not in holidays as well.