dprichard Posted September 10, 2008 Share Posted September 10, 2008 I am trying to pull in birthdays coming up in the next 60 days but am not quite sure how to get it to ignore the year and just compare month and day. Any help would be greatly appreciated. SELECT CONCAT(emp_fname,' ',emp_lname) AS emp_name, DATE_FORMAT(emp_dob, '%W, %M %D') AS birthday FROM Employee WHERE emp_dob >= CURDATE() AND emp_dob <= DATE_ADD(CURDATE(), INTERVAL 60 DAY) ORDER BY emp_dob ASC Tried this as well... No workie... SELECT CONCAT(emp_fname,' ',emp_lname) AS emp_name, DATE_FORMAT(emp_dob, '%W, %M %D') AS birthday FROM Employee WHERE DATE_FORMAT(emp_dob, '%m-%d') BETWEEN DATE_FORMAT(CURDATE(), '%m-%d') AND DATE_ADD(DATE_FORMAT(CURDATE(), '%m-%d'), INTERVAL 30 DAY) ORDER BY emp_dob ASC Quote Link to comment Share on other sites More sharing options...
fenway Posted September 10, 2008 Share Posted September 10, 2008 How can emb_dob be both before & after today's date? Thats' why the first one's not working. You can use MONTH() and DAYOFMONTH() to extract the non-year part. Quote Link to comment Share on other sites More sharing options...
dprichard Posted September 10, 2008 Author Share Posted September 10, 2008 doesn't emp_dob >= CURDATE() mean after todays date, but emp_dob <= DATE_ADD(CURDATE(), INTERVAL 60 DAY) mean before 60 days from now? That is what I was shooting for with that first statement. Thanks for the reply. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 10, 2008 Share Posted September 10, 2008 Sorry, you're right I saw less-than and mis-read... I'm not a fan of DATE_ADD(), I prefer CURDATE() + INTERVAL 60 DAY. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.