LoginSignup
34
36

More than 5 years have passed since last update.

ActiveRecordを指定日時範囲内で取得する方法

Posted at
from = Time.zone.parse("2009-10-06")
to = from + 1.day
Hoge.find(:all, :conditions => {:updated_at => from...to})

#出力されるSQL例: 
Hoge Load (0.0ms)   SELECT * FROM `hoges` WHERE (`hoges`.`updated_at` >= '2009-10-06 15:00:00' AND `hoges`.`updated_at` < '2009-10-07 15:00:00')

Reference

34
36
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
36