Rails ActiveRecord查找日期

Cal*_*bHC 6 sql activerecord ruby-on-rails

我很难搞清楚这一点但是如何告诉我的finder语句忽略db中Datetime字段的时间?

def trips_leaving_in_two_weeks
  Trip.find(:all, :conditions => ["depart_date = ?", 2.weeks.from_now.to_date])
end
Run Code Online (Sandbox Code Playgroud)

我希望depart_date回来作为一个约会,但它也会不断返回时间并导致这种平等不起作用.有什么方法可以与日期进行比较吗?谢谢

编辑

这是我现在使用的代码:

Trip.find(:all, :conditions => ["DATE(depart_date) = ?", 2.weeks.from_now.to_date])
Run Code Online (Sandbox Code Playgroud)

Pet*_*own 7

不确定您使用的是哪个数据库,但这有用吗?

"depart_date = DATE(?)"
Run Code Online (Sandbox Code Playgroud)

  • 反过来尝试:`"DATE(depart_date)=?",2.weeks.from_now.to_date`它应该工作. (4认同)