[thelist] mysql/php - choosing a suitable date format

Dunstan Orchard dunstan at 1976design.com
Thu Feb 6 09:18:02 CST 2003


> > So, what format do I store the thing in?
>
> date
>
> http://www.mysql.com/doc/en/DATETIME.html

Thanks Rudy, thanks Bill. I had read all the pages at that URL but I was a bit
confused by the amount of information, and when you don't know if it's
relevant or not it's easy to miss the glaringly obivous points in there :o)

I have to say now I'm using the date setting that it's excellent, it makes
selecting months or days or whatever a dream.

If anyone else hasn't used this before here's an example of how easy it is to
grab the names of months from 2003-02-01 type dates:


Create a drop down of months where events are taking place:

// query
$query = ("SELECT DISTINCT MONTHNAME(date) as month FROM wildevent ORDER BY
month ASC");

// run query
$result = mysql_query($query);

while ($row = mysql_fetch_array($result))
 {
 $month = $row["month"];

 print "<option value=\"$month\">$month</option>\r\n";
 }



Select the records based on the user's selection of a month:

$query = ("SELECT * FROM wildevent WHERE (MONTHNAME(date) = '$date') ORDER BY
date ASC");


Easy peasy, but then I'm sure that _you_ all knew that!

Thanks very much - dunstan

---------------------------
Dorset, England
http://www.1976design.com/
http://www.orchard.it/
http://www.maccaws.org/



More information about the thelist mailing list