Skip to content

Instantly share code, notes, and snippets.

@bensie
Created February 23, 2009 19:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bensie/69110 to your computer and use it in GitHub Desktop.
Save bensie/69110 to your computer and use it in GitHub Desktop.
Get upcoming birthdays with SQL (discarding the year)
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