Hi Friends ,

I got a row in my table like follows

date | Name | id
--------------------------
22-August | Ram | 15
14-July | Krish | 17
14_March | Anwar | 145
---------------------------

I want to sort this with date ie,

14-March
14-Jusy
22-August


Using both date and month ......
Please help me

Thanks in advance
Thank you for your valuable time
Rajeesh

Recommended Answers

All 2 Replies

You should set up the "date" column as a true date field, not as a character field. Then you could sort by this field.

It is confusing to name a column 'date' because DATE is a datatype. The creator of the table should have created a DATE type column with a better name. If you have no choice but to try and sort this table without altering the design, try the following:

mysql> select * from test ORDER BY STR_TO_DATE(date, '%d-%M');
+-----------+-------+-----+
| date      | Name  | id  |
+-----------+-------+-----+
| 14_March  | Anwar | 145 | 
| 14-July   | Krish |  17 | 
| 22-August | Ram   |  15 | 
+-----------+-------+-----+
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.