Can’t compare naive and aware datetime.now()

I am trying to compare the current date and time with dates and times specified in models using comparison operators:

if challenge.datetime_start <= datetime.now() <= challenge.datetime_end:

The script errors out with:

TypeError: can't compare offset-naive and offset-aware datetimes

The models look like this:

class Fundraising_Challenge(models.Model):
    name = models.CharField(max_length=100)
    datetime_start = models.DateTimeField()
    datetime_end = models.DateTimeField()

I also have django using locale date and times.

What I haven’t been able to find is the format django uses for DateTimeField(). Is it naive or aware? And how do I get datetime.now() to recognize locale datetime?

9 Answers
9

Leave a Comment