Why This Happens
datetime.date and datetime.datetime are different types. You cannot subtract one from the other. Convert both to the same type first.
The Problem
from datetime import date, datetime
today = date.today()
now = datetime.now()
delta = now - todayThe Fix
from datetime import date, datetime
today = date.today()
now = datetime.now()
delta = now.date() - today # Convert datetime to dateStep-by-Step Fix
- 1
Convert to same type
Use .date() on datetime, or datetime.combine(date, time.min).
- 2
Check data types
Use type() to verify date vs datetime.
- 3
Be consistent
Use datetime throughout, convert to date only for display.
Got the actual stack trace?
Paste it into our free AI explainer to get the cause and the fix for your specific case — no signup, nothing to install.
Explain my errorBugsly catches this automatically
Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.
Try Bugsly free