On 02 Oct 2009, at 13:12, adedip wrote:
> I've this entry with a Date attribute, in the yyyy-mm-dd form.
>
> I need to retrieve all the articles in a data Range, nothing of what I
> read really worked..what's the matter?
>
> Using find(:all, :conditions .... )
> I've tryed:
> - date between ? and ?
> - date => from..to
> - year(date)
>
> nothing happened..is ruby able to evaluate range for Dates?
> please show me the way :S
If and only if your date field in the database is a date or a time:
Model.all(:conditions => {:date => 7.days.ago..Date.today})
Model.all(:conditions => ["date BETWEEN ? AND ?",
7.days.ago ,Date.today])
both generate and return valid results:
SELECT * FROM `models` WHERE (`models`.`date` BETWEEN '2009-09-25
12:35:21' AND '2009-10-02')
I prefer the first notation, but tastes might differ.
Best regards
Peter De Berdt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---