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

浙公网安备 33010602011771号