hello, im stuck, im trying to do a find on a model with a date range where i only have 1 date. example something like def self.date_range(posted_date) date_range = find(:all, :conditions => { :received_date => posted_date..24.hours }) return date_range end basically i pass in the posted date from another object and get responses back based on the responses where the response_date = the post_date + 24.hours or something along those lines. any help would be great, hopefully i explained it ok. thanks
This should help: http://morecode.wordpress.com/2007/01/14/querying-for-a-date-range-ruby-on-rails/ On Sep 9, 8:32 am, Bob O <sngndn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hello, > > im stuck, im trying to do a find on a model with a date range where i > only have 1 date. > > example something like > > def self.date_range(posted_date) > date_range = find(:all, :conditions => { :received_date => > posted_date..24.hours }) > return date_range > end > > basically i pass in the posted date from another object and get > responses back based on the responses where the response_date = the > post_date + 24.hours or something along those lines. > > any help would be great, hopefully i explained it ok. > > thanks
Ruby handles date ranges as integers internally so it is a bad idea to try that. You can do something simpler using the array syntax of conditions :conditions => ["received_date >= ? and received_date <= ?",posted_date, posted_date] This will form the necessary SQL for the database query. On Sep 9, 11:32 am, Bob O <sngndn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hello, > > im stuck, im trying to do a find on a model with a date range where i > only have 1 date. > > example something like > > def self.date_range(posted_date) > date_range = find(:all, :conditions => { :received_date => > posted_date..24.hours }) > return date_range > end > > basically i pass in the posted date from another object and get > responses back based on the responses where the response_date = the > post_date + 24.hours or something along those lines. > > any help would be great, hopefully i explained it ok. > > thanks
Mukund wrote:> Ruby handles date ranges as integers internally so it is a bad idea to > try that. You can do something simpler using the array syntax of > conditions > > :conditions => ["received_date >= ? and received_date > <= ?",posted_date, posted_date] > > This will form the necessary SQL for the database query.Or even better, "received_date between ? and ?". Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.