Hi, I want to create a named scope that returns all the line where date is in X number of days. This is how it looks named_scope :in, lambda { |number| { :conditions => ["event_date = ?", number.days.from_now] } } My problem is that is compares the date with the hours, minutes and seconds and just would to compare the day... How do I do this? Greg -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 jul, 16:28, Greg Ma <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > I want to create a named scope that returns all the line where date is > in X number of days. > This is how it looks > > named_scope :in, lambda { |number| > { :conditions => ["event_date = ?", number.days.from_now] } > } > > My problem is that is compares the date with the hours, minutes and > seconds and just would to compare the day... > How do I do this? > > Greg > -- > Posted viahttp://www.ruby-forum.com/.I think this would work: :conditions => ["event_date between ? and ?", number.days.from_now.beginning_of_day, number.days.from_now.end_of_day] Regards -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
For MySql this would work named_scope :in, lambda {|number| {:conditions => ["date(event_date) = ?", number.days.from_now.to_date]} } Hope that helps. Greg On Jul 12, 2:12 am, Xuan <xua...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 11 jul, 16:28, Greg Ma <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > > > > Hi, > > > I want to create a named scope that returns all the line where date is > > in X number of days. > > This is how it looks > > > named_scope :in, lambda { |number| > > { :conditions => ["event_date = ?", number.days.from_now] } > > } > > > My problem is that is compares the date with the hours, minutes and > > seconds and just would to compare the day... > > How do I do this? > > > Greg > > -- > > Posted viahttp://www.ruby-forum.com/. > > I think this would work: > > :conditions => ["event_date between ? and ?", > number.days.from_now.beginning_of_day, > number.days.from_now.end_of_day] > > Regards-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.