Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sorting - Order By date ASC

Tags:

mysql

I have "date" column in mysql saving the dates with this format
17-09-2014 (DD-MM-YYYY)

I need to sort them ascending, so I used this command:

SELECT * FROM table ORDER BY date ASC

But I found this result:

17-09-2014
18-09-2015
19-09-2014

It should be:

17-09-2014
19-09-2014
18-09-2015

It sorts the day only ASC not the full date

like image 632
Ahmed Avatar asked Sep 17 '14 12:09

Ahmed


People also ask

What does order by ASC mean?

Ascending order means the smallest or first or earliest in the order will appear at the top of the list: For numbers or amounts, the sort is smallest to largest. Lower numbers or amounts will be at the top of the list. For letters/words, the sort is alphabetical from A to Z.

How do you rearrange the DATE in ascending or descending order?

Click Home tab > arrow under Sort & Filter, and then click Sort Oldest to Newest, or Sort Newest to Oldest.

Is order by default DESC or ASC?

You can use the ASC and DESC keywords to specify ascending (smallest value first) or descending (largest value first) order. The default order is ascending.


1 Answers

Try this:

SELECT * FROM table ORDER BY STR_TO_DATE(date,'%d-%m-%Y') ASC
like image 130
Alex Avatar answered Oct 21 '22 19:10

Alex