mysql - SQL select order by date in varchar -
i have date in database in varchar column , can't alter it. want sort things newest latest. date in database looks like:
2014-09-22 10:28:28
so seek like:
$sql = "select * axnmrs_cases vin = :vin order str_to_date(date_created,'%b-%e-%y') asc limit 30";
but unfortunately not alter me , if alter asc desc , nil changeing in result
and like:
$sql = "select * axnmrs_cases vin = :vin order convert(date_created, date, 103)";
this throw syntax sql error , have no thought why.
is here can show me right way?
date stored in varchar not real date , hence order not give want. best approach store date in mysql native info types. in case can utilize str_to_date()
function convert varchar dates real date , utilize sort as
order str_to_date(date_created,'%y-%m-%d %h:%i:%s');
mysql sql
No comments:
Post a Comment