Hey guys, I'm kinda struggling with how to do this query properly. I want to find members in my db table whose birthday was 5 days previous to the current date. This seems to be pretty tricky to my feeble mind.
So far, I have this query which at least matches the birthday correctly. I somehow have to figure out how to do the check for bdays 5 days gone.
SELECT *
FROM members
WHERE MONTH(dob) = MONTH(CURDATE())
AND DAYOFMONTH(dob) = DAYOFMONTH(CURDATE());
Something like this is flawed, but gives an indication of what i开发者_运维问答'm trying to do...
SELECT *
FROM members
WHERE MONTH(dob) = MONTH(CURDATE())
AND DAYOFMONTH(dob) = DATEADD(DAYOFMONTH(CURDATE()), INTERVAL 5 day);
More or less Ike's answer, but if you want their birthdays, not exact dates, something like this should work
SELECT *,
CURRENT_DATE() - INTERVAL 5 DAY AS then
FROM members
WHERE MONTH(dob) = MONTH(then) AND DAYOFMONTH(dob) = DAYOFMONTH(then)
haven't tested it, but give it a try.
Assuming your dob column is a DATE, you can do something like this:
SELECT *
FROM members
WHERE dob = CURRENT_DATE() - INTERVAL 5 DAY
精彩评论