Hello i have two columns: duration (int) an开发者_StackOverflow社区d dateCol (date) in a table. How should i proceed if i want to know when CURDATE() - dateCol will iqual to duration.
ie: CURDATE() - dateCol (2010-05-08) = duration (14 days), and then send an e-amil?
DATE_SUB(CURDATE(), INTERVAL 14 DAY) = datecol
To do what you want you can use DATEDIFF
:
DATEDIFF(NOW(), last_email_date) >= 14
An alternative method is to interval subtraction:
CURDATE() - interval 14 day >= last_email_date
The second can be faster if there is a suitable index.
Note that I've chosen to use an inequality test instead of an equality because this will handle missed emails if your process is offline for one day and is restarted the next day. You should mark the row as handled when you've handled it to prevent more than one email being sent. This will also prevent multiple emails being sent if your process runs more than once per day (this could happen if you restart it to upgrade / bug fix).
精彩评论