SocomNegotiator Posted September 5, 2008 Share Posted September 5, 2008 Well I have a date in my DB table that is entered in by a user through another page. The format is dd/mm/yyyy So I have a date, and when I try to call the info from that table and order by the date. It only orders by the first set of numbers. So by the dd, and not the rest. $query=mysql_query("SELECT * FROM empty_leg ORDER BY date ASC"); So if I had 05/12/2004 and 09/12/1999 the 09/12/1999 should display first, but it doesn't the 05/12/2004 does. What can I do to fix this so that it uses the whole date? Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted September 5, 2008 Share Posted September 5, 2008 The field should be of type date then only it will work. Quote Link to comment Share on other sites More sharing options...
kratsg Posted September 5, 2008 Share Posted September 5, 2008 Short Solution Check the field type to see if it's set as "DATE". Longer, More Flexible Solution The best way that makes it simplest is to convert the date into a unix timestring: $timestamp = mktime(0,0,0,$month,$day,$year); Store that into the database instead. In order to convert it back into the date: $data = date("d/m/Y",$timestamp); This should be a bit easier because: you can use the date function (given any unix-timestamp) to format the output in anyway you like. http://us3.php.net/manual/en/function.date.php Quote Link to comment 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.