Hi,
I am new to Ruby and Rails, so I don’t know if this is my fault, but
maybe this is a bug in Rails (I’m using Rails 3.0 beta) which should be
reported.
I have following search statement:
events = CalendarEvent.find :all, :conditions => { :target_date =>
begin_date..end_date }
which produces following sqlite output:
SELECT "calendar_events".* FROM "calendar_events" WHERE
("calendar_events"."target_date" BETWEEN 2010-03-29 AND
2010-05-03)
The result is WRONG, because sqlite treats 2010-03-29 as number of the
value 1978!
If I write following instead:
events = CalendarEvent.find :all, :conditions => ["target_date
BETWEEN ? AND ?", begin_date, end_date]
I get the right result, which is:
SELECT "calendar_events".* FROM "calendar_events" WHERE
(target_date BETWEEN '2010-03-29' AND '2010-05-02')
Is there another way to specify the needed format? I already checked,
that begin_date and end_date are truly Date values. If I use
Date.new(2010,3,29) f.i. the result is exactly the same.
Thanks!