Python TypeError: can't subtract offset-naive and offset-aware datetimes

Aug 10, 2019

You must make sure both datetime have timezone info, or timezone info of None.

import datetimefrom dateutil import parser as dateutil_parsertoday = # None: no timezone infodate_str = '2019-08-10T00:00:00Z'd = dateutil_parser.parse(date_str)print(d.tzinfo) # tzutc(): this has utc timezone infod = d.replace(tzinfo=None)  # remove timezone infodelta = today - d

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.