How do you make a query where you ORDER BY birthday disregarding the year altogether. I need to eliminate/disregard the year and ORDER BY birthdate month and birthdate day from today's date in either ASC or DESC.
The below won't work because the years of the birthdate come into play. The below example shows what happens when the year is regarded:
John 01/02/1974
Billy 11/15/2000
Ally 06/25/2008
SELECT * FROM users ORDER BY birthdate
Expected results when ordering by birthday:
John 01/02/1974
Ally 06/25/2008
Billy 11/15/2000
EDIT: @AaronBertrand's comment is correct, day-of-year doesn't hold for leap years. You could use his solution. Another way is to order by month and day, like:
SELECT * FROM users ORDER BY month(birthdate), day(birthdate)
This will normalize all dates to the year 2000:
ORDER BY DATEADD(YEAR, 2000-YEAR(birthday), birthday);
This will handle leap year babies correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With