Query datetime by today's date in Django

前端 未结 7 571
梦谈多话
梦谈多话 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:53

    I remember there being plans to add a __date field lookup to make this easier, but as it stands the "standard" way of doing it is

    today_min = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
    today_max = datetime.datetime.combine(datetime.date.today(), datetime.time.max)
    Invoice.objects.get(user=user, date__range=(today_min, today_max))
    

提交回复
热议问题