I am trying to compare the current date and time with dates and times specified in models using comparison operators:
if challenge.datetime_start <= datet
It is working form me. Here I am geeting the table created datetime and adding 10 minutes on the datetime. later depending on the current time, Expiry Operations are done.
from datetime import datetime, time, timedelta
import pytz
Added 10 minutes on database datetime
table_datetime = '2019-06-13 07:49:02.832969' (example)
# Added 10 minutes on database datetime
# table_datetime = '2019-06-13 07:49:02.832969' (example)
table_expire_datetime = table_datetime + timedelta(minutes=10 )
# Current datetime
current_datetime = datetime.now()
# replace the timezone in both time
expired_on = table_expire_datetime.replace(tzinfo=utc)
checked_on = current_datetime.replace(tzinfo=utc)
if expired_on < checked_on:
print("Time Crossed)
else:
print("Time not crossed ")
It worked for me.