Hi, Say I have a Widget that has a created_on field. How can I find: - All widgets that were created last year - All widgets that were created during a certain month - All widgets that were created during a certain week - All widgets that were created during a certain day Do I need to write a SQL finder for this? There could be more than a 100k widgets, so performance would be nice to have. Thanks, Joe --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Model.find(:all, :conditions => [''created_at < ?'', 1.year.ago]) # Created more than 1 year ago Model.find(:all, :conditions => [''created_at > ? AND created_at < ?'', DateTime.new(2006, 3), DateTime.new(2006, 4)]) # Created in March you get the idea... On 12/09/06, joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi, > > Say I have a Widget that has a created_on field. > > How can I find: > - All widgets that were created last year > - All widgets that were created during a certain month > - All widgets that were created during a certain week > - All widgets that were created during a certain day > > Do I need to write a SQL finder for this? There could be more than a > 100k widgets, so performance would be nice to have. > > Thanks, > Joe > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-13 00:45 UTC
Re: Finding by date
Ian Leitch wrote:> Model.find(:all, :conditions => [''created_at < ?'', 1.year.ago]) # Created > more than 1 year ago > Model.find(:all, :conditions => [''created_at > ? AND created_at < ?'', > DateTime.new(2006, 3), DateTime.new(2006, 4)]) # Created in March > > you get the idea...Yes, I do. That''s not hard at all. Should have been obvious. Sometimes I surprise myself with how dumb I am. >:(> On 12/09/06, joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi, > > > > Say I have a Widget that has a created_on field. > > > > How can I find: > > - All widgets that were created last year > > - All widgets that were created during a certain month > > - All widgets that were created during a certain week > > - All widgets that were created during a certain day > > > > Do I need to write a SQL finder for this? There could be more than a > > 100k widgets, so performance would be nice to have. > > > > Thanks, > > Joe > > > > > > > > > > > ------=_Part_204251_2058250.1158085800344 > Content-Type: text/html; charset=UTF-8 > X-Google-AttachSize: 1162 > > Model.find(:all, :conditions => [''created_at < ?'', 1.year.ago]) # Created more than 1 year ago<br>Model.find(:all, :conditions => [''created_at > ? AND created_at < ?'', DateTime.new(2006, 3), DateTime.new(2006, 4)]) # Created in March > <br><br>you get the idea...<br><br><div><span class="gmail_quote">On 12/09/06, <b class="gmail_sendername"><a href="mailto:joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org">joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a></b> <<a href="mailto:joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org">joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > </a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>Hi,<br><br>Say I have a Widget that has a created_on field.<br><br> > How can I find:<br> - All widgets that were created last year<br> - All widgets that were created during a certain month<br> - All widgets that were created during a certain week<br> - All widgets that were created during a certain day > <br><br>Do I need to write a SQL finder for this? There could be more than a<br>100k widgets, so performance would be nice to have.<br><br>Thanks,<br>Joe<br><br><br> > ------=_Part_204251_2058250.1158085800344----~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---