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 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2 Sep 2008, at 14:57, Erwin wrote:> > 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 likeEither have the column be just a date or search a range. Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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, 16:20, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2 Sep 2008, at 14:57, Erwin wrote: > > > > > > > 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 > > Either have the column be just a date or search a range. > > Fred--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
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> god > > thanks > > On 2 sep, 16:20, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 2 Sep 2008, at 14:57, Erwin wrote: >> >> >> >> >> >>> 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 >> >> Either have the column be just a date or search a range. >> >> Fred > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---