2009/10/2 adedip <[email protected]>: > > @Fred of course is a Date type and not string ;) > > On 2 Ott, 14:39, Peter De Berdt <[email protected]> wrote: >> 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]) > > good to know..and thanks for this..but what if a have to choose among > latter periods like from 1993 to 2001? > (I'm dealing with newspaper articles) > And I have in the search form a select with all the available Dates > (in the yyyy-mm-dd) format. > > It could be good to me to only use year, so the question is how the > get only the year from a Date type? I've tryed year(date) but it does > not work (al least in the range actually)..or second aswer do I have > to write a method that calculates how many days ago I want? even for > 1993 ?
Take the date from your form, which I think you are saying is a string in "yyyy-mm-dd" format and convert it into a Date object. Then you can use it in the find conditions as suggested above. Colin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

