How to search for entries in the previous day, starting from 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.
精彩评论