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
Do this in settings.py file :
USE_TZ=False
I was getting the same error, and it has resolved the error
if timezone_aware_var <= datetime.datetime.now(timezone_aware_var.tzinfo):
pass #some code
# Timezone info of your timezone aware variable
timezone = your_timezone_aware_variable.tzinfo
# Current datetime for the timezone of your variable
now_in_timezone = datetime.datetime.now(timezone)
# Now you can do a fair comparison, both datetime variables have the same time zone
if your_timezone_aware_variable <= now_in_timezone:
pass #some code
You must add the timezone info to your now()
datetime.
However, you must add the same timezone of the reference variable; that is why I first read the tzinfo
attribute.
Disable time zone.
Use challenge.datetime_start.replace(tzinfo=None);
You can also use replace(tzinfo=None)
for other datetime.
if challenge.datetime_start.replace(tzinfo=None) <= datetime.now().replace(tzinfo=None) <= challenge.datetime_end.replace(tzinfo=None):