views:

51

answers:

1

My blog posts have a created_at datetime attribute.

How would I use Blog.find to retrieve all blog posts created on a given day (say 1/1/2009) ignoring the time on that day they were created?

+3  A: 

This should be pretty close.

d = DateTime.new(2009, 1, 1)
Blog.find(:all, :conditions => [ "created_at >= ? AND created_at < ?", d.beginning_of_day, d.tomorrow.beginning_of_day ])
Andy Gaskell