Query datetime by today's date in Django

前端 未结 7 495
梦谈多话
梦谈多话 2021-01-31 08:16

I\'m saving datetime in the db for an object. I\'d like to query against the db and select anything from todays date, not datetime.

What\'s the

7条回答
  •  后悔当初
    2021-01-31 08:43

    There is a new __date field lookup in Django 1.9 you can use:

    Entry.objects.filter(pub_date__date=datetime.date(2005, 1, 1))
    Entry.objects.filter(pub_date__date__gt=datetime.date(2005, 1, 1))
    

    Queryset API

提交回复
热议问题