mySQL SELECT upcoming birthdays

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

    try this:

     Select * From persons
     where (DayOfYear(birthday) >= 7 
             And DayOfYear(birthday) - DayOfYear(curdate()) Between 0 and 6) Or
           (MOD(YEAR(curDate()),4) = 0) And MOD(YEAR(curDate()),100) != 0
            And (DayOfYear(birthday) + 366 - DayOfYear(curdate())) % 366 < 7) Or
             (DayOfYear(birthday) + 365 - DayOfYear(curdate())) % 365 < 7)
    

提交回复
热议问题