Asheesh Yadav Asheesh Yadav - 6 months ago 24
SQL Question

How can Select date(dd/mm/yyyy) in ascending order in sql

I want To Select stockDate in ASC Order My

Structure is.:-

enter image description here


You have saved the dates as varchar and they are evil, you should use mysql native date data types.

For this you first need to convert the varchar dates to real date using str_to_date function while doing the sorting, here how it works

mysql> select str_to_date('31/07/2015','%d/%m/%Y') as d ;
| d          |
| 2015-07-31 |

So the query becomes

SELECT * from inventory_details 
ORDER BY str_to_date(stockDate,'%d/%m/%Y') desc