如何找到某个日期创建的所有记录(与今天或昨天等无关)
这是它的格式: irb(main):016:0> SourceNode.first.created_at
我想找到那些在 2013 年 7 月 1 日创建的:
=> Fri, 12 Jul 2013 01:15:48 UTC +00:00
irb(main):017:0> SourceNode.where("created_at = '2013-07-01'").count
=> 0
最佳答案
如果它始终是特定日期,您可以截断日期以进行比较。
SourceNode.where("date_trunc('day', created_at) = '2013-07-01'").count
来源:Postgres的优秀date/time documentation .
关于ruby-on-rails - 如何使用 postgres 在 rails 中查找在某一天(不是今天!)创建的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19871544/