I am trying to compare two dates - today and date from db.
Db date format is 2021-10-04T21:00:00Z
and today date is 2023-08-11 09:06:10
(%Y-%m-%d %H:%M:%S
).
How to compare these dates?
I tried this:
from datetime import datetime
from time import strftime, gmtime
today_time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
date_format = '%Y-%m-%d %H:%M:%S'
due_date = datetime.strptime(date_from_db, date_format)
if due_date < today_time:
# ...
And I get following exception:
ValueError: time data '2021-10-04T21:00:00Z' does not match format '%Y-%m-%d %H:%M:%S'
How to resolve this?