Answer the question
In order to leave comments, you need to log in
How to sort a list taken from db by month and day?
There are users in the database with the date of birth:
1990-05-25
1987-02-04
1994-07-13
I make the list output like this:
SELECT * FROM users WHERE bd!='0' ORDER BY DATE_FORMAT(`bd`, '%Y-%m-%d') DESC
Answer the question
In order to leave comments, you need to log in
1. If you want to sort exactly by month and day without a year, then what the hell are you adding %Y to the date formatting template?
2. If you sort by full date and the bd field has type DATE, DATETIME. TIMESTAMP etc. (i.e. a type designed to store a date) then no perversions with DATE_FORMAT are required - just ORDER BY bd DESC .
3. For the situation when the field is empty, in SQL if the special value is NULL . Crutches in the form of bd!='0' - another nonsense.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question