我想从数据库中获取今天 create_at 的所有记录。但是当我这样做的时候
Model.where('DATE(created_at) = ?',Date.today)
它只返回今天创建的最后一条记录。我有 3 条记录 created_at
2015-03-03 11:38:31
2015-03-03 11:59:00
2015-03-03 11:33:04
.但它仅返回此 created_at 日期为“2015-03-03 11:38:31”的记录。
还提到了 How to delete all records created today? , Getting all rows created today .我想知道为什么会这样? 也试过
Model.where("DATE(created_at) = ?",Date.today)
和
Tracking::TrackingLogin.where("created_at >= ?", Time.zone.now.beginning_of_day)
请有人解释一下我的代码中发生了什么?
最佳答案
尝试以下操作:
Model.where("created_at >= ?", Time.zone.now.beginning_of_day)
关于ruby-on-rails - 获取今天在 Rails 中创建的所有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28831447/