'"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '00:00:00'

I have a Django app, where I use raw SQL query to get some item with date before some date.

In view.py file I have to query the CourseInfo table to get the courses before a specific date.

View.py:

query_results = CourseInfo.objects.raw('SELECT * FROM TABLE_course WHERE  first_semester <= %s' % (datetime(2021, 1, 1)))

But I got this error: 1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '00:00:00' at line 1

How could I fix this error?

ps: courseinfo model

class CourseInfo(TimeStampedModel):  
 code = models.CharField(max_length=20, db_index=True)

 title = models.CharField(max_length=190)

 discipline = models.ForeignKey(Discipline, on_delete=models.SET_NULL, 
        blank=True, null=True)  # should not be null
 discipline_code = models.CharField(max_length=20, blank=True, null=True)
 
 first_semester = models.DateField(default=False)


 def __str__(self):

    return "{}".format(self.title)


 class Meta:
    
    ordering = ['code', ]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source