I have an automatic checker that checks for domains that are going to expire within the next 7 days and it sends and email to the customer.
Im using this SQL Query:
Assuming your expiry date is a correct datetime field
expiry_date=DATE_ADD(NOW(), INTERVAL 7 DAY)
more reliable than
expiry_date=DATE(NOW() + INTERVAL 7 DAY)
Actually thinking about it if you want exactly 7 days in the future you'd have to use a datediff too
Something like this to return only requests where the expiry date is exactly 7 days from today.
DATEDIFF(expiry_date,DATE(NOW() + INTERVAL 7 DAY))=7
Though this isn't fool proof you're better off letting it check against all days between now and 7 days in the future and then if it is setting an "email sent" flag in your database so then you can confirm the email was actually sent rather than blindly trusting a script to have worked.