ActiveRecord DateTime type search range

i have a table full of entries that each have a datetime field with a
date and timestamp… how would i use activerecord to get all entries
from say 2008-08-12 12:00:00 to 2009-08-12 12:00:00… i’ve tried
searching the table in every way i can think of and can’t seem to find
it online

On 2 Aug 2008, at 20:54, Morgan M. wrote:

i have a table full of entries that each have a datetime field with a
date and timestamp… how would i use activerecord to get all entries
from say 2008-08-12 12:00:00 to 2009-08-12 12:00:00… i’ve tried
searching the table in every way i can think of and can’t seem to find
it online

SomeClass.find :all, :conditions => {:date_field =>
(first_date…second_date)}
or
SomeClass.find :all, :conditions => [‘date_field > ? and date_field
< ?’, first_date, second_date]

Fred

warning…
I have been using range with ActiveSupport::TimeWithZone values
(start_at, end_at) stored in DateTime columns in my DB
check what this range will output : period = start_at…end_at
vs period = Date.parse(start_at.to_s)…Date.parse(end_at.to_s)
you will be surprised…