Comparing datetimes in Python

You always want to convert datetime objects to UTC before comparing them. Why is that, you ask? I am sure there are plenty of other reasons, but we recently discovered a serious footgun at work: Comparing “timezone-based” datetime objects fails during DST transition! I will explain this using the DST transition from CEST to CET in Germany (the is the transition on the last Sunday in October, from “Sommerzeit” to “Winterzeit”, where wall clocks are turned back one hour), so our timezone is "Europe/Berlin". ...

October 28, 2025 · 4 min