我想查詢其due_date(datetime數據類型)比當天多3天的記錄。我想在他們到期日的3天之前將剩餘的郵件發送給人們。因爲我正在寫這個查詢。如何在rails中從當前日期獲取截止日期多於3天的記錄?
remind_invoices = Invoice.where("status = ? AND (due_date - 3) == ?", "unpaid", Date.today)
同樣地,我想送其餘郵件說你的截止日期已經過去,(在這種情況下,截止日期是過去的日期。)我想對那些如果我們增加3天,768,16等於獲取這些記錄到當天。簡單地說,我想在截止日期的3天后發送電子郵件。爲此我目前的查詢是這樣的。
unpaid_invoices = Invoice.where("status = ? AND (due_date + 3) == ?", "unpaid", Date.today)
像
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '== '2016-12-17')' at line 1: SELECT `invoises`.* FROM `invoises` WHERE (status = 'unpaid' AND (due_date - 3) == '2016-12-17')
ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '== '2016-12-17')' at line 1: SELECT `invoises`.* FROM `invoises` WHERE (status = 'unpaid' AND (due_date - 3) == '2016-12-17')