gpt4 book ai didi

ruby-on-rails - 将 Date 和 1.month.ago 放在一起?

转载 作者:数据小太阳 更新时间:2023-10-29 07:21:04 25 4
gpt4 key购买 nike

当我有一个名为 :purchase_date 的日期属性并想将它放在一起时,如何将 Date1.month.ago 放在一起在类方法中?

def self.last_month # Show only products of last month.
where(:purchase_date => Date.today.1.month.ago.end_of_month..Date.1.month.ago.beginning_of_month)
end

console 给出语法错误并将其删除 Date.today 与我的其他方法相比,结果为空白:

def self.this_month # Show only products of this month.
where(:purchase_date => Date.today.beginning_of_month..Date.today.end_of_month)
end

最佳答案

只需 1.month.ago 就足够了,您不需要在 1.month.ago 之前添加 Date.today 因为1.month.ago 从今天开始

关于ruby-on-rails - 将 Date 和 1.month.ago 放在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8521027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com