Sort upcoming birthdays based on current date

后端 未结 5 951
庸人自扰
庸人自扰 2020-12-06 08:01

I have the following table of people and their birthdays:

name        birthday
----------------------
yannis      1979-06-29
natalia     1980-08-19
kostas            


        
5条回答
  •  时光说笑
    2020-12-06 08:35

    i would try it like this (but this isn't tested):

    SELECT
      name,
      birthday
    FROM
      birthdays
    ORDER BY
      ABS( DAYOFYEAR(birthday) - (DAYOFYEAR(CURDATE()) ) ASC
    

    EDIT:
    changed ordering from DESC to ASC because you want to get the farthest first, not the closest.

提交回复
热议问题