Answers for "convert offset naive to offset aware"

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 "convert offset naive to offset aware"

Python Answers by Framework

Browse Popular Code Answers by Language