我正在尝试使用此范围执行此操作:
>> Job.last.application_date
Job Load (0.4ms) SELECT "jobs".* FROM "jobs" ORDER BY created_at ASC LIMIT 1
=> Wed, 13 Feb 2013
>> Date.today + 5.days
=> Wed, 13 Feb 2013
>> Job.where(application_date: Date.today + 5.days)
Job Load (0.2ms) SELECT "jobs".* FROM "jobs" WHERE "jobs"."application_date" = '2013-02-13' ORDER BY created_at DESC
=> []
更新
嗯,那不行,可能是因为有些数据格式。>> Job.where("application_date = ?", Date.today + 5)
Job Load (0.3ms) SELECT "jobs".* FROM "jobs" WHERE (application_date = '2013-02-13') ORDER BY created_at DESC => []
>> Job.last.application_date Job Load (0.7ms)
SELECT "jobs".* FROM "jobs" ORDER BY created_at ASC LIMIT 1 => Wed, 13 Feb 2013
# Schema jobs
# application_date :date
答案 0 :(得分:2)
您可以使用:
where("application_date = ?", Date.today + 5)