Cyto Posted March 14, 2012 Share Posted March 14, 2012 Hello, I would like to order by date that contains day and month, like this: 14-3 Is this possible? Quote $sql = mysql_query("SELECT * FROM date WHERE online='1'"); Link to comment https://forums.phpfreaks.com/topic/258946-mysql-order-by-date/ Share on other sites More sharing options...
requinix Posted March 14, 2012 Share Posted March 14, 2012 Why aren't you using a DATE or DATETIME column? Link to comment https://forums.phpfreaks.com/topic/258946-mysql-order-by-date/#findComment-1327471 Share on other sites More sharing options...
Cyto Posted March 14, 2012 Author Share Posted March 14, 2012 because i'm adding it from admin. See it as adding a event in a calendar. Link to comment https://forums.phpfreaks.com/topic/258946-mysql-order-by-date/#findComment-1327475 Share on other sites More sharing options...
Psycho Posted March 14, 2012 Share Posted March 14, 2012 Quote because i'm adding it from admin. See it as adding a event in a calendar. Huh? I'm not following. You should always store dates/times as appropriate date and/or time formats in the database. You can always convert the value into whatever format you want in the output. Link to comment https://forums.phpfreaks.com/topic/258946-mysql-order-by-date/#findComment-1327478 Share on other sites More sharing options...
Cyto Posted March 14, 2012 Author Share Posted March 14, 2012 Is there a way to covert 14-3 to what you mean and order it? Link to comment https://forums.phpfreaks.com/topic/258946-mysql-order-by-date/#findComment-1327480 Share on other sites More sharing options...
cpd Posted March 14, 2012 Share Posted March 14, 2012 Quote Is there a way to covert 14-3 to what you mean and order it? Change the field type to DATE and alter your code to format the date as YYYY-MM-DD. Then either write a script to convert existing dates, even though you don't have the year :s, or do it manually (long). Link to comment https://forums.phpfreaks.com/topic/258946-mysql-order-by-date/#findComment-1327487 Share on other sites More sharing options...
Cyto Posted March 15, 2012 Author Share Posted March 15, 2012 I founded out myself. Using STR_TO_DATE(date, '%d-%m') ASC. Link to comment https://forums.phpfreaks.com/topic/258946-mysql-order-by-date/#findComment-1327499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.