Jump to content

[SOLVED] PHP/MYSQL


SocomNegotiator

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.