How do I match an entire day to a datetime field?

后端 未结 3 1169
不知归路
不知归路 2020-12-11 12:09

I have a table for matches. The table has a column named matchdate, which is a datetime field.

If I have 3 matches on 2011-12-01:

3条回答
  •  醉话见心
    2020-12-11 12:51

    Just use the SQL BETWEEN function like so:

    SELECT * FROM table WHERE date BETWEEN '2011-12-01' AND '2011-12-02'
    

    You may need to include times in the date literals, but this should include the lover limit and exclude the upper.

    From rails I believe you can do:

    .where(:between => '2011-12-01'..'2011-12-02')
    

提交回复
热议问题