可能是愚蠢的问题,但它现在让我发疯。为什么
User.where(:created_at => 1.day.ago..Time.now).count
(0.8ms) SELECT COUNT(*) FROM "users" WHERE ("users"."created_at" BETWEEN '2012-11-06 17:58:22.443552' AND '2012-11-07 17:58:22.443809')
=> 2
和
User.where(:created_at => 1.day.ago.to_date..Time.now.to_date).count
(0.6ms) SELECT COUNT(*) FROM "users" WHERE ("users"."created_at" BETWEEN '2012-11-06' AND '2012-11-07')
=> 0
给我一个不同的结果?
我知道如果没有时间(使用 .to_date ),一天的开始和结束应该需要午夜。这就是我想要的,但由于一些晦涩的原因,它显示为 0,但我在 10 分钟前创建了 2 个用户......