How to get all the records of previous week?

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?


Post.find(:conditions => [“updated_at BETWEEN ? AND ?”,,])

2008/1/13, Ryan Bigg :

Post.find(:conditions => ["updated_at BETWEEN ? AND

Post.find :all, :conditions => { :updated_at => 2.weeks.ago..1.week.ago }

should work.

   -- Jean-François.

You could make that condition shorter by referring to the times as 2.weeks.ago and 1.week.ago. :slight_smile:


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 :

You can also write :
and so on.


   -- Jean-François.