Alex Rivera | Logout

How to find a record created on the previous month?

Asked 2009-02-02T09:31:24.263
11

I have a table where new records are added daily. How would I go about finding records created in the previous month?

Edit
Report

2 Answers

3

Assuming your records are timestamped, you can just do something like this:

Thing.find(:all, :conditions => ["created_at > ?", Time.now - 1.month])

If they're not timestamped, you should start storing the information since it's something you'll want to look up later.

answered 2009-02-02T10:01:05.453
1

Thanks everyone, I ended up going with this:

find(:all, :conditions => ['created_at > ? AND created_at < ?', Date.today.last_month.beginning_of_month, Date.today.beginning_of_month])
answered 2009-02-03T01:39:59.067

Your Answer