Marvil Joy
Marvil Joy

Reputation: 662

Sql date between query with a date and number of days

I have a table called Renewals as follows

id | item_name | next_renewal_date | alert_before_days
2  | Test      | 2015-05-25        |  5
6  | Test4     | 2015-05-12        |  2
7  | Test7     | 2015-05-30        |  12

I would like to read the table by alert_before_days. For example, i need the rows with upcoming renewals by its alert_before_days from current date onwards.

I'm using cakephp and tried the following, but nothing works. it only selects the date as 1970-01-01

'conditions'=>array('Renewal.NextRenewalDate <=' =>  date('Y-m-d', strtotime("+Renewal.AlertBeforeDays days"))

Upvotes: 2

Views: 84

Answers (1)

Sougata Bose
Sougata Bose

Reputation: 31749

strtotime will not recognize that expression. Do it with mysql -

'conditions'=>array(
     'Renewal.NextRenewalDate <=' => 'DATE_ADD(NOW() + INTERVAL `Renewal`.`NextRenewalDate` DAY)'
)

Upvotes: 2

Related Questions