Named_scope with dates

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

On 11 jul, 16:28, Greg Ma [email protected] wrote:

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

For MySql this would work

named_scope :in, lambda {|number|
{:conditions => [“date(event_date) = ?”,
number.days.from_now.to_date]}
}

Hope that helps.

Greg

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs