django Queryset with year(date) = '2010'

后端 未结 2 1362
旧巷少年郎
旧巷少年郎 2021-01-03 23:47

I\'m trying to build this query

select * from m_orders where year(order_date) = \'2010\' 

the field order_date is a DateTime field. I just

相关标签:
2条回答
  • 2021-01-03 23:57

    You can achieve this without using raw SQL. Use the built in __ mechanism instead (see the documentation for more details). Something like this:

    MyOrder.objects.filter(order_date__year = 2010)
    
    0 讨论(0)
  • 2021-01-04 00:10

    you can use django's builtin query API for this. no need for any vendor specific code or raw SQL.

    it would probably look something like this:

    Orders.objects.filter(order_date__year=2010)
    

    http://docs.djangoproject.com/en/dev/topics/db/queries/

    0 讨论(0)
提交回复
热议问题