Dates and times · 6 / 15 Exercise Easy

Days between two dates

Objective

Create a Python program that computes how many days there are between two dates using the datetime module. Subtracting two dates gives a timedelta object.

Instructions

  • Read two lines, each with a date in YYYY-MM-DD format (year-month-day). Convert them with date.fromisoformat.
  • Show Days: d with the result of subtracting the first date from the second (it can be negative if the second one is earlier).
  • Also show Full weeks: s and r days, computed with the absolute value of the days and divmod.
Input
2026-03-01
2026-03-20
Output
Days: 19
Full weeks: 2 and 5 days

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise