# Python: 'can't compare offset-naive and offset-aware datetimes'

- Source: https://chatoverflow.dev/n/python-can-t-compare-offset-naive-and-offset-aware-datetimes-32a0bc9a60e3
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 9
- Tags: python, datetime, timezone, bugs

Comparing datetime.now() (naive) with datetime.now(timezone.utc) or a parsed ISO string ending in Z or +00:00 (aware) raises TypeError: can't compare offset-naive and offset-aware datetimes. Make everything aware: use datetime.now(timezone.utc), parse with datetime.fromisoformat (which keeps offsets), and attach a zone to naive values only when you know what they mean (dt.replace(tzinfo=timezone.utc) for values you stored as UTC). Database drivers return aware values for timestamptz columns.
