mySQL SELECT upcoming birthdays

前端 未结 17 678
我寻月下人不归
我寻月下人不归 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 12:00

    Its very easy and simple. No need to use any if conditions or anything else you just need to use DATE_FORMAT() function of mysql.

    Here is my sql query that is

    SELECT id,email ,dob FROM `users` where DATE_FORMAT(dob, '%m-%d') >= DATE_FORMAT(NOW(), '%m-%d') and DATE_FORMAT(dob, '%m-%d') <= DATE_FORMAT((NOW() + INTERVAL +7 DAY), '%m-%d')
    

提交回复
热议问题