Compare date of datetime object in filter django

I use django 3.1.0

I have a release_time field(a DateTimeFeild) in my model, and i want to retrieve those records that have been released in current date.

here is my model:

class Test(models.Model):
  title = models.CharField(max_length=100)
  release_time = models.DateTimeField()
  end_time = models.DateTimeField()

I use the following line to get my data:

cur_time = localtime() // django.utils.timezone.localtime
Test.objects.filter(release_time__date=cur_time.date())

This always returns an empty query set. I am sure that there are records that have this condition.

PLease tell me am I doing this wrong??



Read more here: https://stackoverflow.com/questions/64952233/compare-date-of-datetime-object-in-filter-django

Content Attribution

This content was originally published by fuse13 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: