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 Link to comment https://forums.phpfreaks.com/topic/123654-filter-by-month-day-date-regardless-of-year/ 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. Link to comment https://forums.phpfreaks.com/topic/123654-filter-by-month-day-date-regardless-of-year/#findComment-638631 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. Link to comment https://forums.phpfreaks.com/topic/123654-filter-by-month-day-date-regardless-of-year/#findComment-638635 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. Link to comment https://forums.phpfreaks.com/topic/123654-filter-by-month-day-date-regardless-of-year/#findComment-638649 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.