[Rails] Subtract a field from the current time in MySQL?
Jean-François
jf.web3 at gmail.com
Tue Jul 25 21:47:30 GMT 2006
Hello Ben,
> Table Products:
> With a column called "purchased_at" of type "datetime".
>
> Products.find(:all, :conditions => ["? - purchased_at >= 120",
> Time.now])
>
> Why doesn't that work? What I'm trying to do is find records that were
> purchased less than or equal to 2 minutes ago.
Try sth like :
Product.find(:all, :conditions => [ "purchased_at > ?",
2.minutes.ago.to_s(:db) ])
-- Jean-François.
--
À la renverse.
More information about the Rails
mailing list