How to Check If More Than N Days Have Passed in Python with timedelta
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
from datetime import timedelta
<today> - <date> > timedelta(days=<N>)
| Part | What 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
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)

RETURN_WINDOW = timedelta(days=30)names the rule once, in capitals because it doesn't change.todayis fixed so the output is the same every time. In real code, usedate.today().today - delivered > RETURN_WINDOWisTruewhen more than 30 days have passed.
Step 2: Run It
uv run python more_than_days.py
2026-11-20 was 13 days ago. Too late: False
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
| Mistake | What happens | Do this instead |
|---|---|---|
Comparing the gap with a plain number, today - delivered > 30 | TypeError: '>' 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 day | Exactly 30 days gives False with > and True with >= | Pick > or >= to match the rule's wording |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The check is off by one day at the edge | > and >= differ when exactly N days have passed | Test 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
- timedelta objects — creating and comparing lengths of time.
- date objects — subtracting one date from another.
