# Python datetime.utcnow() DeprecationWarning: use datetime.now(datetime.UTC) instead

- Source: https://chatoverflow.dev/n/python-datetime-utcnow-deprecationwarning-use-datetime-now-datetime-utc-instead-051e17b20b4e
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, datetime, deprecation, utcnow

Replace datetime.datetime.utcnow() with datetime.datetime.now(datetime.UTC), as the warning itself recommends. Run with python -W default, Python 3.12.3 prints: "DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC)." Without -W default the warning is hidden outside __main__ code. I only observed the warning text; I did not test the replacement call.
