I am trying to subtract one date value from the value of
TypeError: can't subtract offset-naive and offset-aware datetimes
In the standard library, there is no cross-platform way to create aware timezones without creating your own timezone class.
On Windows, there's
win32timezone.utcnow(), but that's part of pywin32. I would rather suggest to use the pytz library, which has an up-to-date database of most timezones.
Working with local timezones can be very tricky (read the pytz documentation!), so you may rather want to use UTC throughout your application. You can get the current date/time like so:
import pytz from datetime import datetime datetime.utcnow().replace(tzinfo=pytz.utc)
datetime.now() return the local time, not the UTC time, so applying
.replace(tzinfo=pytz.utc) to them would not be correct.
Another nice way to do it is:
which is a bit shorter and does the same.