preloader
軟體工程

Inquiry Rails ActiveRecord records between two dates

Follow below code for inquiring ones in ActiveRecord between two dates:

YourModel.find(:date => somenumber.days.ago..Date.today)

# or
YourModel.find(:created_at => yourNumber.years.ago..Date.today)

# or
YourModel.find(:updated_at => yourVariable.months.ago..Date.yesterday)

 

Aboved code are modified from a post at stackoverflow.com.

Reference: http://stackoverflow.com/questions/2381718/rails-activerecord-date-between