Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my column data is 1-jul,16-jul,5-jul,7-jul,15-jul,28-jul,10-jul i want this order by date


1-jul,5-jul,7-jul,10-jul,15-jul,28-jul

What I have tried:

select date from table order by date
Posted
Updated 18-Aug-16 1:36am

Don't store it like that: never store dates a strings, it always gives problems later.
Instead, store it as DATETIME values and as individual rows in a table, not as comma separated values, with a foreign key back to the other table row they relate to. Generating a stored CSV list from that is almost trivial, where sorting by date a string based list of CSV data is possible but really pretty complicated. And it will cause other problems later as well, which are as complicated to fix.

Change your DB, and always store data in appropriate types.
 
Share this answer
 
Quote:
How to order by date in mysql
As you can see, it is a bad idea to store dates in common human form if you want to do something bigger than just read that date as is.
So the advice is never do it that way.
Date is a complicated data type and the computer must know that it is a date to be able to handle it.
Most languages have a DateTime data type because it is a very common data with very specific operations.
If you need to store a date as a string, the most practical format is "yyyymmdd", which gives "20160818" for today. this mostly what DateTime is doing internally.

For your problem, since the dates are stored in a bad form, you have to create a program to deal with them. Your program will read a string date split it in components and rebuild a string that will match this format "yyyymmdd" just to be able to sort the data. If you need to count days between dates, you have to do another program.
Transforming the string to DateTime type would simplify things.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900