Converting times for db query

Picking up a rails project for the first time in a few months and drawing a blank here…
I want to compare a created_at datetime field in a find() call
@users_week = User.count( :conditions => “created_at > ‘#{
7.days.ago}’”)
MySQL doesn’t like the format of that date so I added this:
class Time
def to_db
self.strftime("%Y-%m-%d %H:%M:%S.0")
end
end
and then:
@users_week = User.count( :conditions => “created_at > ‘#{7.days.ago.to_db}’”)

I’m sure there is a ‘dead simple’ way to do this

thanks

Mr Bear -

Haha - I new it! It’s been too long… thanks

Well, if it’s “dead simple” that you want, why not:

@users_week = User.count( :conditions => [“created_at > ?”, 7.days.ago])

Then you let the database adapter worry about both the formatting (which Rails gives you as 7.days.ago.to_s(:db) anyway, no need to define your own) and the quoting.

-Rob

Rob Biedenharn http://agileconsultingllc.com

Rob@AgileConsultingLLC.com

That works as well - thank you.