[Rails] 簡易Model年月區間篩選方法
MODEL
scope :with_year_and_month, ->(year, month) {
date = DateTime.new(year,month)
where(created_at: date...date.next_month)
}
# => created_at >= '2015-02-01 00:00:00' AND created_at < '2015-03-01 00:00:00'
scope :with_year_and_month, ->(year, month) {
date = DateTime.new(year,month)
where(created_at: date...date.next_month)
}
# => created_at >= '2015-02-01 00:00:00' AND created_at < '2015-03-01 00:00:00'
留言