开发者

How to search for entries in the previous day, starting from 8:00 AM?

开发者 https://www.devze.com 2023-02-07 00:51 出处:网络
In Rails 2.3.6 I\'d like to search the database for entries between today 8:00 AM and previous d开发者_如何转开发ay at 8:00 AM.

In Rails 2.3.6 I'd like to search the database for entries between today 8:00 AM and previous d开发者_如何转开发ay at 8:00 AM.

Is there an easy way to do this?

Thanks in advance, Augusto


Under Rails 3, example below retrieves users created in range you need:

today8am = Time.now.at_beginning_of_day + 8.hours
@users = User.where("created_at BETWEEN ? AND ?", today8am - 1.day, today8am)

If there may be many records and query is called very often I suggest to add index on date column.

0

精彩评论

暂无评论...
验证码 换一张
取 消