I have a datetime column and I need to search by a date, not datetime. So obviously, I cannot do this: find(:all, :conditions => [''my_datetime_column = ?'', Date.today]) All I want to do is find the records on a datetime column that match today''s date. What I have had to do is convert each record in the datetime column to a date and compare (== Date.today), which is slower than just using a conditions option. What do you guys suggest? Thanks for any help! --~--~---------~--~----~------------~-------~--~----~ 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 20 Mar 2008, at 02:44, jko170 wrote:> > I have a datetime column and I need to search by a date, not datetime. > > So obviously, I cannot do this: > > find(:all, :conditions => [''my_datetime_column = ?'', Date.today]) > > All I want to do is find the records on a datetime column that match > today''s date.You want to say [''my_datetime_column >= ? and my_datetime_column < ?'', Date.today(), Date.today()+1] This works because the dbs I know of handle ''2007-04-20'' as being ''2007-04-20 00:00:00''. If you db does something different you''ll have to adjust for that. Fred> > > What I have had to do is convert each record in the datetime column to > a date and compare (== Date.today), which is slower than just using a > conditions option. What do you guys suggest? > > Thanks for any help! > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Works perfectly! Thank you! On Mar 20, 3:15 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 20 Mar 2008, at 02:44, jko170 wrote: > > > > > I have a datetime column and I need to search by a date, not datetime. > > > So obviously, I cannot do this: > > > find(:all, :conditions => [''my_datetime_column = ?'', Date.today]) > > > All I want to do is find the records on a datetime column that match > > today''s date. > > You want to say [''my_datetime_column >= ? and my_datetime_column < ?'', > Date.today(), Date.today()+1] > This works because the dbs I know of handle ''2007-04-20'' as being > ''2007-04-20 00:00:00''. If you db does something different you''ll have > to adjust for that. > > Fred > > > > > What I have had to do is convert each record in the datetime column to > > a date and compare (== Date.today), which is slower than just using a > > conditions option. What do you guys suggest? > > > Thanks for any help!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can also use CURDATE() if you are using MySQL Model.find(:all, :conditions =>[''created_on <= CURDATE()''], :limit => 10) Model.find(:all, :conditions => [''my_datetime_column = CURDATE()'']) On Thu, Mar 20, 2008 at 11:28 AM, jko170 <jko170-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Works perfectly! Thank you! > > On Mar 20, 3:15 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > On 20 Mar 2008, at 02:44, jko170 wrote: > > > > > > > > > I have a datetime column and I need to search by a date, not datetime. > > > > > So obviously, I cannot do this: > > > > > find(:all, :conditions => [''my_datetime_column = ?'', Date.today]) > > > > > All I want to do is find the records on a datetime column that match > > > today''s date. > > > > You want to say [''my_datetime_column >= ? and my_datetime_column < ?'', > > Date.today(), Date.today()+1] > > This works because the dbs I know of handle ''2007-04-20'' as being > > ''2007-04-20 00:00:00''. If you db does something different you''ll have > > to adjust for that. > > > > Fred > > > > > > > > > What I have had to do is convert each record in the datetime column to > > > a date and compare (== Date.today), which is slower than just using a > > > conditions option. What do you guys suggest? > > > > > Thanks for any help! > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ah, it is not working as expected. I have a record with the datetime of 7pm last night (central time). I''m using tztime so when I do this: Model.find(:all, :conditions => [''datetime_column >= ? and datetime_column < ?'', TzTime.now.to_date, TzTime.now.to_date + 1]) It is showing up in the records for today when it should be yesterday. Is there maybe a way I can just search the date in the datetime column? On Mar 20, 11:27 am, "Michael Steinfeld" <mikeisgr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You can also use CURDATE() if you are using MySQL > > Model.find(:all, :conditions =>[''created_on <= CURDATE()''], :limit => 10) > > Model.find(:all, :conditions => [''my_datetime_column = CURDATE()'']) > > On Thu, Mar 20, 2008 at 11:28 AM, jko170 <jko...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Works perfectly! Thank you! > > > On Mar 20, 3:15 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On 20 Mar 2008, at 02:44, jko170 wrote: > > > > > I have a datetime column and I need to search by a date, not datetime. > > > > > So obviously, I cannot do this: > > > > > find(:all, :conditions => [''my_datetime_column = ?'', Date.today]) > > > > > All I want to do is find the records on a datetime column that match > > > > today''s date. > > > > You want to say [''my_datetime_column >= ? and my_datetime_column < ?'', > > > Date.today(), Date.today()+1] > > > This works because the dbs I know of handle ''2007-04-20'' as being > > > ''2007-04-20 00:00:00''. If you db does something different you''ll have > > > to adjust for that. > > > > Fred > > > > > What I have had to do is convert each record in the datetime column to > > > > a date and compare (== Date.today), which is slower than just using a > > > > conditions option. What do you guys suggest? > > > > > Thanks for any help!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Woops! Nevermind. It is a timezone problem not a query problem. On Mar 20, 5:44 pm, jko170 <jko...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ah, it is not working as expected. I have a record with the datetime > of 7pm last night (central time). I''m using tztime so when I do this: > > Model.find(:all, :conditions => [''datetime_column >= ? and > datetime_column < ?'', TzTime.now.to_date, TzTime.now.to_date + 1]) > > It is showing up in the records for today when it should be yesterday. > Is there maybe a way I can just search the date in the datetime > column? > > On Mar 20, 11:27 am, "Michael Steinfeld" <mikeisgr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > You can also use CURDATE() if you are using MySQL > > > Model.find(:all, :conditions =>[''created_on <= CURDATE()''], :limit => 10) > > > Model.find(:all, :conditions => [''my_datetime_column = CURDATE()'']) > > > On Thu, Mar 20, 2008 at 11:28 AM, jko170 <jko...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Works perfectly! Thank you! > > > > On Mar 20, 3:15 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > On 20 Mar 2008, at 02:44, jko170 wrote: > > > > > > I have a datetime column and I need to search by a date, not datetime. > > > > > > So obviously, I cannot do this: > > > > > > find(:all, :conditions => [''my_datetime_column = ?'', Date.today]) > > > > > > All I want to do is find the records on a datetime column that match > > > > > today''s date. > > > > > You want to say [''my_datetime_column >= ? and my_datetime_column < ?'', > > > > Date.today(), Date.today()+1] > > > > This works because the dbs I know of handle ''2007-04-20'' as being > > > > ''2007-04-20 00:00:00''. If you db does something different you''ll have > > > > to adjust for that. > > > > > Fred > > > > > > What I have had to do is convert each record in the datetime column to > > > > > a date and compare (== Date.today), which is slower than just using a > > > > > conditions option. What do you guys suggest? > > > > > > Thanks for any help!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---