一个日期在我的数据库看起来是这样的:2012-07-23
Rails日期比较;日期大于或等于天前
我想看看,如果日期是早于7天前,小于14天前或看日期是更大超过14天,但我有没有运气..
这里是我的代码:
def progress_report_status_check(date)
progress_date = date.to_date
seven_days = 7.days.ago.to_date
fourteen_days = 14.days.ago.to_date
if seven_days > (progress_date - 7.days.ago.to_date) or (progress_date - 14.days.ago.to_date) < fourteen_days
"due"
elsif (progress_date - 14.days.ago.to_date) > fourteen_days
"overdue"
end
end
您是否在使用Rails? Ruby没有天方法。你需要ActiveSupport – revolver 2012-08-02 01:46:31
对不起,我忘了补充说,我正在使用Rails 3 – dennismonsewicz 2012-08-02 01:47:02