即将到来 从今天开始的 3 天 b/w 两个日期 rails 目前它只计算今天

upcoming 3 day from today b/w two dates rails currently it calculate only for today

def self.leave_day 
 self.where("? BETWEEN start_date AND end_date", Date.today).where(status: "Approved").count
end

但我想计算从今天到接下来的 3 天。现在计算 b/w 状态为今天的两个日期,如果给定日期范围 (Date.today +1)..( =16=] + 3.days) 不接受

可以在 where 上使用多个参数。

我觉得应该是这样的:

def self.leave_day 
  self.where("start_date >= ? AND end_date <= ?", Date.today, Date.today + 3.days).where(status: "Approved").count
end

来源:https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-where

不接受范围是什么意思?你可以用一个范围来做到这一点,并将 start_date 设置为日期的开始,将 end_date 设置为一天的结束。

def self.leave_day 
 self.where(start_date: (Date.today.beginning_of_day)..((Date.today + 3.days).end_of_day), status: 'Approved').count
end