MySql: Fixed sort datetime string field dd-mm-yyyy
If you using a system where the dates are stored as strings in the format dd/mm/yyyy or dd-mm-yyyy. Is it possible to convert this to yyyy-mm-dd in a sort Query.
Table:Product
Table:Product
year ---- 20-08-2015 02-03-2010 03-03-2011 02-03-2011 02-04-2011
SELECT `year` FROM `Product` WHERE 1 order BY DATE_FORMAT(STR_TO_DATE(`year`, '%d-%m-%Y'), '%Y-%m-%d') DESC
Comments
Post a Comment