Answers for "python TypeError: can't subtract offset-naive and offset-aware datetimes"

2

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

import dateutil, datetime, pytz
LastDate = dateutil.parser.parse('2020-06-06 00:00:00+00:00')
now = datetime.datetime.now()
# Remove the TimeZone extension.
if (now - LastDate.replace(tzinfo=None) ).days >1:
    print("This works")
# OR, make current datetime aware of the timezone
now = pytz.utc.localize(now)
if (now - LastDate ).days >1:
    print("This works too")
Posted by: Guest on June-06-2020

Code answers related to "python TypeError: can't subtract offset-naive and offset-aware datetimes"

Python Answers by Framework

Browse Popular Code Answers by Language