How do I sort a date field entered by the datepicker script in the format dd-mm-yyyy in Mysql?
Note: Dates are being sorted only by day, ignoring the next month and year. And the date field is of type varchar (10).
Ex: 02-05-2018 (dd-mm-yyyy)
How do I sort a date field entered by the datepicker script in the format dd-mm-yyyy in Mysql?
Note: Dates are being sorted only by day, ignoring the next month and year. And the date field is of type varchar (10).
Ex: 02-05-2018 (dd-mm-yyyy)
Because the date is in string
it will sort the data by "-" , you need to convert the field to date
select
*
from tabela
order by str_to_date(data, '%d-%m-%Y') desc
I've put an example in SQLFiddle for reference.