I have a field in Post called updated_at which of DATETIME type. I want to get all the posts which were updated last week. How do I do that? Thanks -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Post.find(:conditions => ["updated_at BETWEEN ? AND ?",Time.now-2.weeks, Time.now-1.week]) On Jan 13, 2008 10:05 PM, Vapor .. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have a field in Post called updated_at which of DATETIME type. I want > to get all the posts which were updated last week. How do I do that? > > Thanks > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
2008/1/13, Ryan Bigg :> Post.find(:conditions => ["updated_at BETWEEN ? AND > ?",Time.now-2.weeks,Time.now-1.week])Post.find :all, :conditions => { :updated_at => 2.weeks.ago..1.week.ago } should work. -- Jean-François. --~--~---------~--~----~------------~-------~--~----~ 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 could make that condition shorter by referring to the times as 2.weeks.ago and 1.week.ago. :) RSL On Jan 13, 2008 6:41 AM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Post.find(:conditions => ["updated_at BETWEEN ? AND ?",Time.now-2.weeks, > Time.now-1.week]) > > On Jan 13, 2008 10:05 PM, Vapor .. < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > > > I have a field in Post called updated_at which of DATETIME type. I want > > to get all the posts which were updated last week. How do I do that? > > > > Thanks > > -- > > Posted via http://www.ruby-forum.com/. > > > > http://www.frozenplague.net > > Feel free to add me to MSN and/or GTalk as this email. > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Jan 13, 2008, at 5:41 AM, Ryan Bigg wrote:> Post.find(:conditions => ["updated_at BETWEEN ? > AND ?",Time.now-2.weeks,Time.now-1.week])I took it to mean he was asking for "last week," as on the calendar. So no matter if today is Monday or Thursday, "last week" would still refer to the same period of time. Just as ''last month'' would right now mean December. Anyway, I was hoping to find an elegant answer to that in this thread, as the way I do that stuff is downright ugly. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
2008/1/13, George Bailey <listcatcher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > Post.find(:conditions => ["updated_at BETWEEN ? > > AND ?",Time.now-2.weeks,Time.now-1.week]) > > > I took it to mean he was asking for "last week," as on the calendar. > So no matter if today is Monday or Thursday, "last week" would still > refer to the same period of time. Just as ''last month'' would right now > mean December. > > Anyway, I was hoping to find an elegant answer to that in this thread, > as the way I do that stuff is downright ugly.You can look at : Time.now.beginning_of_week Date.today.beginning_of_week You can also write : Date.today.beginning_of_month and so on. HTH, -- Jean-François. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---