Python timedelta: Days Between Two Dates
Subtract one date from another and Python gives a timedelta: the gap between them. Its .days is the number of days between the two dates.
Read datetime first.
Days between two dates
Subtract the earlier date from the later one, then read .days.
from datetime import date
start = date(2026, 2, 1)
end = date(2026, 3, 1)
gap = end - start
print(gap)
print(gap.days)
gap is a timedelta, which prints as 28 days, 0:00:00. gap.days is the
plain number 28.
Count down to a date
A countdown is the target date minus today.
from datetime import date
today = date(2026, 11, 3)
holidays = date(2026, 12, 18)
print((holidays - today).days, "days to go")
This uses a fixed date for today so the answer stays the same. In a real
program, write today = date.today().
Add days to a date
Make a timedelta with days= or weeks=, then add it to a date or take it
away.
from datetime import date, timedelta
borrowed = date(2026, 3, 25)
due = borrowed + timedelta(days=14)
print(due)
print(due - timedelta(weeks=1))
Fourteen days after 25 March is 8 April. Python moves into the next month for you.
Minutes between two times
Subtracting two datetime values gives hours and minutes too.
.total_seconds() turns the whole gap into seconds.
from datetime import datetime
start = datetime(2026, 3, 14, 9, 15)
finish = datetime(2026, 3, 14, 11, 45)
took = finish - start
print(took)
print(took.total_seconds() / 60, "minutes")
The gap prints as 2:30:00, which is 150.0 minutes.
Note: .days counts whole days only, so a gap of a few hours has
.days of 0. .seconds is not the whole gap either: it is only the
seconds left over after the whole days. Use .total_seconds() for the full
length.
See also: datetime, Format and parse dates.
Your turn
Print the number of days from start to end, then print the date 100
days after start.
from datetime import date, timedelta
start = date(2026, 1, 1)
end = date(2026, 12, 25)
# add two prints: the days from start to end, then the date 100 days after start
Expected output
358
2026-04-11