Omer Omer - 6 months ago 15
SQL Question

Get results order by date in MySQL if date field's datatype is varchar

I want to get results ordered by date from a table in mysql but the problem is the date column's datatype is

varhcar


Here is the table structure:

-------------------------------------------
ID EVENT DATE
-------------------------------------------
1 My Wife’s Birthday 23-02-1987
2 Wedding Anniversary 18-05-2006
3 My Son’s Birthday 06-12-2014
4 Ramadan 08-06-2016
-------------------------------------------
INT VARCHAR VARCHAR


Here is the query
SELECT event_date FROM events ORDER BY CONVERT(event_date, DATETIME)


Im using
CONVERT
but I think I'm doing it wrong. Can anyone help?

Answer

use STR_TO_DATE() function

order by str_to_date(`DATE`, '%d-%m-%Y')