Home mysql Sort by date in MySQL - months are displayed in the reverse...

Sort by date in MySQL – months are displayed in the reverse order.




When sorting by date, sorting occurs in numbers, but months are displayed in the reverse order – November, October.
Here is a query:

select *, date_format (date, '% d% m% y') as `date` tor

Table Where
Start = ‘$ search’ and End =
‘$ search1’ and date between
Curdate () and Curdate () + Interval 2

What to fix it to be removed all right – days and months ascending?

Answer 1, Authority 100%

Desc – sorting from more to a smaller.
ASC – from smaller to more.

Answer 2, Authority 100%

In this example, I would have done so at the end:

Order by unix_timestamp (str_to_date (date , '% y-% m-% d')) DESC

I note – % y-% M-% D In this order, part of the date are located in the database.

and yes, it seems easier so. And more – date like a reserved word in mysql .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions