I am trying to subtract one date value from the value of datetime.datetime.today()
to calculate how long ago something was. But it complains:
TypeError: can't subtract offset-naive and offset-aware datetimes
The value datetime.datetime.today()
doesn't seem to be "timezone aware", while my other date value is. How do I get a value of datetime.datetime.today()
that is timezone aware?
Right now, it's giving me the time in local time, which happens to be PST, i.e. UTC - 8 hours. Worst case, is there a way I can manually enter a timezone value into the datetime
object returned by datetime.datetime.today()
and set it to UTC-8?
Of course, the ideal solution would be for it to automatically know the timezone.
datetime.now().astimezone()
since Python 3.6 – johnchen902from datetime import datetime, timezone; datetime.now(timezone.utc).astimezone()
– FutureNerddatetime.date
objects can't have an associated time zone, onlydatetime.datetime
objects can. So the question is aboutdatetime.datetime.today
, and not aboutdatetime.date.today
, which are different. I've edited the question to make this slightly clearer. – Flimm