Php mysql add 1 year to date then compare if that new date will come in 30 days

Hello,

I have been writing a small script that would suppose to check the expiration date 30 days prior to that date and send email reminder.

I have a table with column named ‘completed’ meaning the date whene the course has been finished, completed. Each course is valid for 1 year.

What I have been trying to do is first add one full year to ‘completed’ then check if that new date falls exactly 30 days prior to now().

Example: the course was finished on 31 Dec 2012. It is valid until 31 Dec 2013, so if TODAY is 1 Dec 2013 email reminder should be sent.

I have this little script:


SELECT distinct
    userID
    , completed+INTERVAL 1 YEAR AS expires
  FROM activity
WHERE completed > NOW() + INTERVAL 30 DAY

but obviously it doesn’t do the job…
Could anyone point me into right direction?

Thanks!
Cheers,
Greg

WHERE completed + INTERVAL 1 YEAR < CURRENT_DATE + INTERVAL 30 DAY

i think :slight_smile:

Exactly would make it WHERE completed + INTERVAL 1 YEAR = CURRENT_DATE + INTERVAL 30 DAY.