mcerveni Posted March 18, 2009 Share Posted March 18, 2009 Here's what happens when I ORDER BY date... Date ----- 3/1/2009 3/10/2009 3/11/2009 3/12/2009 3/14/2009 3/16/2009 3/2/2009 2/3/2009 2/6/2009 Here's my query: $sql = "SELECT * FROM import_stats WHERE EmpID = '$searchreq' || AgentName = '$searchreq' || AvayaID = '$searchreq' ORDER BY date"; Why is that? Quote Link to comment https://forums.phpfreaks.com/topic/150021-order-by-date-not-ordering-properly/ Share on other sites More sharing options...
Zane Posted March 18, 2009 Share Posted March 18, 2009 make sure the date field is of a date datatype wow...say that 10 times fast Quote Link to comment https://forums.phpfreaks.com/topic/150021-order-by-date-not-ordering-properly/#findComment-787856 Share on other sites More sharing options...
gijew Posted March 18, 2009 Share Posted March 18, 2009 Actually, it's ordering it perfectly. What is the field type? Is it varchar or date/datetime? I'm thinking if it's set to varchar mysql is going to treat it like regular alpha/numeric and sort it like that. Switch to a date/datetime field type and it should sort properly. Quote Link to comment https://forums.phpfreaks.com/topic/150021-order-by-date-not-ordering-properly/#findComment-787858 Share on other sites More sharing options...
mcerveni Posted March 18, 2009 Author Share Posted March 18, 2009 hmm.. i changed my date to 1-mar-09 and when i changed the date field to DATE or DATETIME, it won't accept it . it will say: #1292 - Incorrect datetime value: '1-Mar-09' for column 'date' at row 1 Quote Link to comment https://forums.phpfreaks.com/topic/150021-order-by-date-not-ordering-properly/#findComment-787908 Share on other sites More sharing options...
Zane Posted March 18, 2009 Share Posted March 18, 2009 what do you suppose that means? maybe it's in the incorrect format try 2009-03-01 Quote Link to comment https://forums.phpfreaks.com/topic/150021-order-by-date-not-ordering-properly/#findComment-787917 Share on other sites More sharing options...
Rodis Posted March 18, 2009 Share Posted March 18, 2009 make sure the date field is of a date datatype wow...say that 10 times fast wow wow wow wow wow wow wow wow wow wow Quote Link to comment https://forums.phpfreaks.com/topic/150021-order-by-date-not-ordering-properly/#findComment-787961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.