Skip to main content

How to Check If More Than N Days Have Passed in Python with timedelta

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

Return windows, trial periods and password expiry all ask the same question: have more than N days passed since a date? In Python you subtract the dates and compare the result with a timedelta of N days. This guide checks a 30-day return window for two deliveries, with real output from Python 3.15.2.

Syntax​

Syntax
from datetime import timedelta

<today> - <date> > timedelta(days=<N>)
PartWhat it means
<today> - <date>The time that has passed, a timedelta
timedelta(days=<N>)A length of N days to compare with
>True when more than N days have passed

Python's datetime documentation: "timedelta objects support equality and order comparisons."

Prerequisites​

  • uv and Python. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with uv init.

Step 1: Write the Script​

more_than_days.py
from datetime import date, timedelta

RETURN_WINDOW = timedelta(days=30)
today = date(2026, 12, 3)

for delivered in [date(2026, 11, 20), date(2026, 10, 15)]:
too_late = today - delivered > RETURN_WINDOW
print(delivered, "was", (today - delivered).days, "days ago. Too late:", too_late)

The more_than_days.py script in a macOS-style code window: a RETURN_WINDOW of 30 days, today set to 3 December 2026, and a loop over two delivery dates that checks whether today minus the delivery date is greater than the window.

  • RETURN_WINDOW = timedelta(days=30) names the rule once, in capitals because it doesn't change.
  • today is fixed so the output is the same every time. In real code, use date.today().
  • today - delivered > RETURN_WINDOW is True when more than 30 days have passed.

Step 2: Run It​

Terminal
uv run python more_than_days.py
Output
2026-11-20 was 13 days ago. Too late: False
2026-10-15 was 49 days ago. Too late: True

The output in a terminal: 2026-11-20 was 13 days ago, too late False, and 2026-10-15 was 49 days ago, too late True.

The November delivery is 13 days old, inside the window. The October one is 49 days old, past it, so too_late is True.

Common Mistakes​

MistakeWhat happensDo this instead
Comparing the gap with a plain number, today - delivered > 30TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'Compare with timedelta(days=30), or compare .days with 30
> when the rule includes the last dayExactly 30 days gives False with > and True with >=Pick > or >= to match the rule's wording

Troubleshooting​

SymptomLikely causeFix
The check is off by one day at the edge> and >= differ when exactly N days have passedTest the exact boundary date

FAQ​

Is .days > 30 the same as > timedelta(days=30)?​

For two dates, yes: their gap is always whole days. Both said False for a gap of exactly 30 days.

How do I write "more than two weeks"?​

timedelta(weeks=2), or timedelta(days=14): both are the same length.

Conclusion​

today - delivered > timedelta(days=30) told the two deliveries apart: 13 days was inside the return window and 49 days was past it.

Additional Resources​