MYSQL How to order this date field

Asked

Viewed 853 times

3

I have a date field with all separate date and need to put in order as I do.. follows example that this not working...

$query = mysql_query("SELECT * FROM `mensagens` ORDER BY `ano`,`mes`,`dia` ASC") or die(mysql_error());

he leaves in order but not in the right order date fields are 2-digit formatting in numbers, type 06 - 04 - 2014

3 answers

3


  • good, worked!!!

1

0

I believe that convert these columns to a date field with str_to_date() solve the sorting problem:

SELECT str_to_date(concat(ano,'-',mes,'-', dia), '%Y-%m-%d') as nova_data FROM datas 
ORDER BY nova_data ASC

Browser other questions tagged

You are not signed in. Login or sign up in order to post.