我在 Active Record 文档中看到,您可以使用大于/小于比较来查询日期。但是,如果您想选择 where date = Date.today 或者我必须查询 date 大于昨天且小于明天的地方怎么办?
如您所见,我在以下查询中正是这样做的,并且查询 Date = today 返回一个空集
1.9.3p286 :096 > Subscription.where("created_at = ?", Date.today).count
(0.5ms) SELECT COUNT(*) FROM `subscriptions` WHERE (created_at = '2013-01-18')
=> 0
对比
1.9.3p286 :098 > Subscription.where("expiration_date < ? AND expiration_date > ?", Date.today + 1, Date.today - 1).count
(0.4ms) SELECT COUNT(*) FROM `subscriptions` WHERE (expiration_date < '2013-01-19' AND expiration_date > '2013-01-17')
=> 1
这是查询今天日期的正确方法还是我错过了什么?