mySQL SELECT upcoming birthdays

前端 未结 17 648
我寻月下人不归
我寻月下人不归 2020-12-03 11:17

I\'m trying to write a query to select users of a database whose birthdays are in the next 7 days.

I\'ve done a lot of research but I can\'t come up with a working s

17条回答
  •  既然无缘
    2020-12-03 11:47

    I managed to get it working with this query. Due mostly to the help of Lobo's answer.

    SELECT * 
    FROM  persons 
    WHERE  DATE_ADD(STR_TO_DATE(birthday, '%m/%d/%Y'), INTERVAL YEAR(CURDATE())-YEAR(STR_TO_DATE(birthday, '%m/%d/%Y')) YEAR) 
                BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY);
    

提交回复
热议问题