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:
You've probably defined expiry_date
as a datetime value, which means your comparisons are incorrect. e.g. you need to use
SELECT ... WHERE date(expiry_date) = date(now() + interval 7 day)
instead (note the wrapping of the +7 day in a date()
operation.
e.g.
Given a table with a date and a datetime field:
+------------+---------------------+
| d | dt |
+------------+---------------------+
| 2013-06-28 | 2013-06-28 08:23:03 |
+------------+---------------------+
Notice how the comparison comes out:
mysql> select d=now(), d=date(now()), dt=now(), dt=date(now()), now() from x;
+---------+---------------+----------+----------------+---------------------+
| d=now() | d=date(now()) | dt=now() | dt=date(now()) | now() |
+---------+---------------+----------+----------------+---------------------+
| 0 | 1 | 0 | 0 | 2013-06-28 08:26:20 |
+---------+---------------+----------+----------------+---------------------+
1 row in set (0.00 sec)
date v.s. datetime = false
date v.s date = true
datetime v.s. datetime = false (hh:mm:ss doesn't match, so not equal)
datetime v.s. date = false (date is expanded out to yyyy-mm-hh 00:00:00 and the hh:mm:ss don't match