Perplexity π€ Posted September 5, 2007 Share Posted September 5, 2007 Hi all, I'm trying to list phone calls in the order of priority.Β My 'callback' field is of type 'datetime'.Β My order by clause isn't making any difference.Β I need the data ordered by date and time. Β Any ideas what's wrong with this: Β SELECT id, companyname, contactname, tel, DATE_FORMAT(callback, '%e/%c/%Y %l:%i %p') AS callback FROM companies WHERE callback > 0 ORDER BY callback ASC Β Β Thanks in advance. Β CptnChainsaw Link to comment https://forums.phpfreaks.com/topic/68050-solved-query-not-ordering-results/ Share on other sites More sharing options...
Perplexity π€ Posted September 5, 2007 Author Share Posted September 5, 2007 I've worked out that the DATE_FORMAT() function is causing this query to fail.Β Anyone know how I can still use this query with the function? Link to comment https://forums.phpfreaks.com/topic/68050-solved-query-not-ordering-results/#findComment-342060 Share on other sites More sharing options...
Merlin π€ Posted September 5, 2007 Share Posted September 5, 2007 What error message are you getting? Link to comment https://forums.phpfreaks.com/topic/68050-solved-query-not-ordering-results/#findComment-342077 Share on other sites More sharing options...
Perplexity π€ Posted September 5, 2007 Author Share Posted September 5, 2007 Problem solved: Β SELECT id, companyname, contactname, tel, STR_TO_DATE(DATE_FORMAT(callback, '%e/%c/%Y %l:%i %p'), '%e/%c/%Y %l:%i %p') AS callback FROM companies WHERE callback > 0 ORDER BY callback ASC Link to comment https://forums.phpfreaks.com/topic/68050-solved-query-not-ordering-results/#findComment-342079 Share on other sites More sharing options...
Perplexity π€ Posted September 5, 2007 Author Share Posted September 5, 2007 My last query works but it doesn't display the date with the formatting I expect (dd/mm/yyyy hh:mm am/pm) instead it outputs it as yyyy-mm-dd hh:mm:ss Β Β Any idea why? Β Β Β Cheers again, Β CptnChainsaw Link to comment https://forums.phpfreaks.com/topic/68050-solved-query-not-ordering-results/#findComment-342097 Share on other sites More sharing options...
Merlin π€ Posted September 5, 2007 Share Posted September 5, 2007 I see no reason to double up the format. Before you added STR_TO_DATE, what errors messages were you getting? Link to comment https://forums.phpfreaks.com/topic/68050-solved-query-not-ordering-results/#findComment-342166 Share on other sites More sharing options...
Perplexity π€ Posted September 5, 2007 Author Share Posted September 5, 2007 I agree it should've worked straight away as I'm using a datetime field type.Β However it just didn't order the results.Β Calling the function to explicitely convert to a date type did the trickΒ - not sure why though.Β I wasn't getting any errors it just didn't produce the correct results. Β Thnks for your replies btw Β CC Link to comment https://forums.phpfreaks.com/topic/68050-solved-query-not-ordering-results/#findComment-342182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.