Ruby on Rails 日期查询方法

查询近三个月的数量

Order.where(' created_at >= ? ', DateTime.now - 3.month).count

查询上个月的数量

Order.where(created_at: (DateTime.now - 1.month).beginning_of_month..DateTime.now.beginning_of_month).count

查询本月的数量

Order.where(' created_at >= ? ', DateTime.now.beginning_of_month).count

近一周

Order.where(' created_at >= ? ', DateTime.now - 7.day).count
posted @ 2020-04-16 16:42  Mr-Ran  阅读(362)  评论(0编辑  收藏  举报