Reputation: 41
I want To Select stockDate in ASC Order My Table
Structure is.:-
Upvotes: 0
Views: 8716
Reputation:
SELECT * from inventory_details
ORDER BY str_to_date(stockDate,'%d/%m/%Y') desc
Upvotes: 2
Reputation: 1858
Change the date format to YYYY-MM-DD
SELECT * from inventory_details ORDER BY stockDate ASC;
Upvotes: 0
Reputation: 44844
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
Upvotes: 5