Checkin date issue

in my DB, I have records with a DateTIme ‘starting_at’ date

in my model, I wrote a named_scope :

named_scope :planned_on_date, lambda {|aDate|
  {:conditions => ['state = ? AND starting_at = ?', 'planned',

aDate]}
}

the problem is the time… , I only need to get all planned records on
a defined date
aDate = aDate.to_date => Wed, 10 Dec 2008 nned to get all records at
this date whatever time…

if I do
Checkin.planned_on_date(aDate) then => []

is there a simple way to do that ? or should I use a range ?
something like

named_scope :planned_on_date, lambda {|aBeginningDate,

anEndingDate|
{:conditions => ['state = ? AND starting_at BETWEEN ? AND ',
‘planned’, aBeginningDate.change(:hour => 0, :minutes => 0, :seconds
=> 0, aBeginningDate.change(:hour => 23, :minutes => 59, :seconds =>
59) )]}
}

all enlightment welcome

erwin

On 2 Sep 2008, at 14:57, Erwin wrote:

the problem is the time… , I only need to get all planned records on
a defined date
aDate = aDate.to_date => Wed, 10 Dec 2008 nned to get all records at
this date whatever time…

if I do
Checkin.planned_on_date(aDate) then => []

is there a simple way to do that ? or should I use a range ?
something like

Either have the column be just a date or search a range.

Fred

did not realize that I could use the MySQL DATE() function …

named_scope :planned_on_date, lambda {|aDate|
  {:conditions => ['state = ? AND DATE(starting_at) = ?',

‘planned’, aDate] }
}

god

thanks

On 2 Sep 2008, at 16:20, Erwin wrote:

did not realize that I could use the MySQL DATE() function …

named_scope :planned_on_date, lambda {|aDate|
{:conditions => [‘state = ? AND DATE(starting_at) = ?’,
‘planned’, aDate] }
}

You can do that. it will be slower that searching on a range.

Fred

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