I have a DateTimeField
named created_at
in my model. I Would like to query the objects which are created today. From this question I have used the following query set,
In [70]: today = datetime.datetime.today().date()
In [72]: Business.objects.filter(created_at__date=today)
Out[72]: <QuerySet []>
It returns zero results. I have make sure that there is an entry in the database, which was created today. I know that I can also use
Business.objects.filter(created_at__contains=today)
But it yields results with a warning:
django/db/backends/mysql/base.py:71: Warning: (1292, "Incorrect datetime value: '%2017-12-21%' for column 'created_at' at row 1")
I'm using MySQL database. My Model is
class Business(models.Model):
name = models.CharField(max_length=255, blank=True, null=True)
url = models.CharField(max_length=255, blank=True, null=True)
created_at = models.DateTimeField()
category = models.CharField(max_length=120)
class Meta:
managed = False
db_table = 'Business'
unique_together = (('name', 'url'),)