Query datetime by today's date in Django

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

    To get entries from the Last 24 hours you can use:

    from datetime import datetime, timedelta
    
    Entry.objects.filter(pub_date__gte = datetime.now() - timedelta(days=1)) 
    

提交回复
热议问题