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
https://forums.phpfreaks.com/topic/122826-solved-phpmysql/
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
https://forums.phpfreaks.com/topic/122826-solved-phpmysql/#findComment-634292
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.