Mysql Rails 3:从今天起3天内查找datetime为的记录

Mysql Rails 3:从今天起3天内查找datetime为的记录,mysql,ruby-on-rails-3,activerecord,Mysql,Ruby On Rails 3,Activerecord,我有以下范围: def coming_up_on_renewal(product_name = "product_name") where('billing_start_date = NOW() + INTERVAL 3 day AND status = ? AND product_name = ? AND auth_net_subscription_id IS NOT NULL', :active, "#{product_name}") end 我已经在我的数据库中操纵了一条记录,在未来

我有以下范围:

def coming_up_on_renewal(product_name = "product_name")
  where('billing_start_date = NOW() + INTERVAL 3 day AND status = ? AND product_name = ? AND auth_net_subscription_id IS NOT NULL', :active, "#{product_name}")
end
我已经在我的数据库中操纵了一条记录,在未来3天内,但是当我运行这个作用域时,返回了一个空数组

我基本上是在尝试检索记录,其中
计费开始日期
距离当前日期3天。

试试这个

def coming_up_on_renewal(product_name)
  where(:status => :active, :product_name => product_name)
  .where(:billing_start_date => 
   (3.days.from_now.beginning_of_day)..(3.days.from_now.end_of_day))
  .where('auth_net_subscription_id IS NOT NULL')
end
有关附加的“不为空”条件,请参阅。

尝试一下

def coming_up_on_renewal(product_name)
  where(:status => :active, :product_name => product_name)
  .where(:billing_start_date => 
   (3.days.from_now.beginning_of_day)..(3.days.from_now.end_of_day))
  .where('auth_net_subscription_id IS NOT NULL')
end

有关附加的“不为空”条件,请参阅。

运行activerecord语句时,我收到一个错误:
语法错误,意外',',应为tASSOC…名称,'billing_start_date=?',3.days.from_now)
感谢您的帮助!我可以通过以下内容获得它:
where(:status=>:active,:product\u name=>product\u name,:billing\u start\u date=>(Time.now.midnight+3.day)…(Time.now.end\u of_day+3.day)).where('auth\u net\u subscription\u id不为NULL')
我已经编辑了我的答案,尽管我对
billing\u start\u date部分不满意。时间
3.days。从现在开始
它将查找具有确切时间戳的记录,一直到第二个。你可能会寻找更多的日期范围。我更改了我的范围以匹配你的最新编辑。。。很好用!现在包括你的反馈。谢谢。我在运行activerecord语句时出错:
语法错误,意外',',应为tASSOC…名称,'billing_start_date=?',3.days.from_now)
谢谢您的帮助!我可以通过以下内容获得它:
where(:status=>:active,:product\u name=>product\u name,:billing\u start\u date=>(Time.now.midnight+3.day)…(Time.now.end\u of_day+3.day)).where('auth\u net\u subscription\u id不为NULL')
我已经编辑了我的答案,尽管我对
billing\u start\u date部分不满意。时间
3.days。从现在开始
它将查找具有确切时间戳的记录,一直到第二个。你可能会寻找更多的日期范围。我更改了我的范围以匹配你的最新编辑。。。很好用!现在包括你的反馈。谢谢