开发者

compare datetime in find conditions

I am trying to get all users that are updated maximum 90 seconds ago:

User.find(:all, :include => { :core => :image }, 
      :conditions => ["updated_a开发者_Go百科t > ?", Time.now - 90.seconds] )

But it doesn't work.

why?

how can i do?

thanks


If you set config.time_zone in your environment.rb to anything other than UTC, you need to do

User.find(:all, :include => { :core => :image }, 
      :conditions => ["updated_at > ?", Time.now.utc - 90.seconds] )

I'm going to assume that image is an attribute of an association called core?


Do you need to specify users.updated_at


It can be time zone problem. Try to find out Time.now - 1.day, if it'll work, so set your Time.zone in application controller.

And second, you can try your construction without :include option if it cause your problem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜