'How can Select date(dd/mm/yyyy) in ascending order in sql
Solution 1:[1]
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
Solution 2:[2]
SELECT * from inventory_details
ORDER BY str_to_date(stockDate,'%d/%m/%Y') desc
Solution 3:[3]
Change the date format to YYYY-MM-DD
SELECT * from inventory_details ORDER BY stockDate ASC;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Abhik Chakraborty |
Solution 2 | |
Solution 3 | Silambarasan |