query where date = Date.today with Rails, MySQL, and Active Record

后端 未结 3 1083
日久生厌
日久生厌 2021-02-12 23:11

I see in the Active Record docs, you can query for a date using a greater than / less than comparison. However, what if you want to select where date = Date.today or must I quer

3条回答
  •  佛祖请我去吃肉
    2021-02-13 00:12

    I think this is a DUP of this question:

    How to select date from datetime column?

    Subscription.where("DATE(created_at) = ?", Date.today).count
    

    I'm pretty sure this works in MySQL and PostgreSQL, but I'm not sure if it's a SQL standard.

    Wikipedia seems to think TO_DATE would be the standard: http://en.wikipedia.org/wiki/SQL#Date_and_time

    That didn't work for me in PostgreSQL though.

提交回复
热议问题