I have a datetime field in the database. How do I find records for a particular date regardless of the time of day? The method I''m trying does not work.. tasks.find(:all, :conditions => ["date == ?", Date.today]) -- _________________________________ Joshua S. Martin CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney client or other legal privileges, and or proprietary non public information. If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution, or reproduction of this message and or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful. -- 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 Apr 27, 9:07 pm, Joshua Martin <josmar52...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a datetime field in the database. How do I find records for a > particular date regardless of the time of day? >you need to search for records where that date column falls in the appropriate range (ie midnight on that day until midnight on the following day0 Fred> The method I''m trying does not work.. tasks.find(:all, :conditions => ["date > == ?", Date.today]) > > -- > _________________________________ > > Joshua S. Martin > > CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s), > contains information that may be confidential, protected by the attorney > client or other legal privileges, and or proprietary non public information. > If you are not an intended recipient of this message or an authorized > assistant to an intended recipient, please notify the sender by replying to > this message and then delete it from your system. Use, dissemination, > distribution, or reproduction of this message and or any of its attachments > (if any) by unintended recipients is not authorized and may be unlawful. > > -- > 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 athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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.
Ah, I see. Thanks! On Tue, Apr 27, 2010 at 4:20 PM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Apr 27, 9:07 pm, Joshua Martin <josmar52...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I have a datetime field in the database. How do I find records for a > > particular date regardless of the time of day? > > > you need to search for records where that date column falls in the > appropriate range (ie midnight on that day until midnight on the > following day0 > > Fred > > The method I''m trying does not work.. tasks.find(:all, :conditions => > ["date > > == ?", Date.today]) > > > > -- > > _________________________________ > > > > Joshua S. Martin > > > > CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s), > > contains information that may be confidential, protected by the attorney > > client or other legal privileges, and or proprietary non public > information. > > If you are not an intended recipient of this message or an authorized > > assistant to an intended recipient, please notify the sender by replying > to > > this message and then delete it from your system. Use, dissemination, > > distribution, or reproduction of this message and or any of its > attachments > > (if any) by unintended recipients is not authorized and may be unlawful. > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > > For more options, visit this group athttp:// > groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- _________________________________ Joshua S. Martin CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney client or other legal privileges, and or proprietary non public information. If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution, or reproduction of this message and or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful. -- 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 Apr 27, 2010, at 4:24 PM, Joshua Martin wrote:> Ah, I see. Thanks! > > On Tue, Apr 27, 2010 at 4:20 PM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > wrote: > > > On Apr 27, 9:07 pm, Joshua Martin <josmar52...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I have a datetime field in the database. How do I find records for a > > particular date regardless of the time of day? > > > you need to search for records where that date column falls in the > appropriate range (ie midnight on that day until midnight on the > following day0 > > Fred > > The method I''m trying does not work.. tasks.find(:all, :conditions > => ["date > > == ?", Date.today]) >You might also be able to use date functions of your database engine to simplify the query (although depending on indexing, it may not be more performant). tasks.find(:all, :conditions => [''DATE(date) = ?'', Date.today]) Be careful with a range that entries that happen to fall exactly on midnight aren''t counted on both the preceding and following days. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://gaslightsoftware.com Rob-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org> > -- > > _________________________________ > > > > Joshua S. Martin > -- > _________________________________ > > Joshua S. Martin-- 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.
Rob Biedenharn wrote:> Be careful with a range that entries that happen to fall exactly on > midnight aren''t counted on both the preceding and following days.User.find(:all, :conditions => { :created_at => (Date.today)...(Date.today + 1) }) SELECT * FROM "users" WHERE ("users"."created_at" >= ''2010-04-28'' AND "users"."created_at" < ''2010-04-29'') -- 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 Tue, Apr 27, 2010 at 4:07 PM, Joshua Martin <josmar52789-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a datetime field in the database. How do I find records for a > particular date regardless of the time of day? > > The method I''m trying does not work.. tasks.find(:all, :conditions => ["date > == ?", Date.today])You might want to look at http://github.com/radar/by_star Just discovered this in the past few days. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.