Created
February 23, 2009 19:00
-
-
Save bensie/69110 to your computer and use it in GitHub Desktop.
Get upcoming birthdays with SQL (discarding the year)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT users.`firstname` AS first, | |
users.`lastname` AS last, | |
user_details.`birthday` AS birthday | |
FROM users | |
LEFT OUTER JOIN user_details ON user_details.user_id = users.id | |
WHERE | |
STR_TO_DATE(DATE_FORMAT(birthday,'%m-%d'),'%m-%d') >= STR_TO_DATE(DATE_FORMAT(now(),'%m-%d'),'%m-%d') | |
AND | |
STR_TO_DATE(DATE_FORMAT(birthday,'%m-%d'),'%m-%d') < STR_TO_DATE(DATE_FORMAT(now()+INTERVAL 7 DAY,'%m-%d'),'%m-%d'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment