RE: [PHP] mysql select and date functions
| From: | John W. Holmes | Date: | Wed, 19 Feb 2003 02:22:59 +0000 |
| Subject: | RE: [PHP] mysql select and date functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-136101@lists.php.net to get a copy of this message | ||
> Change your query:
> select dayofmonth(Posted) as DOM_Posted,
> month(Posted) as M_Posted,
> year(Posted)as Y_Posted,
> hour(Posted) as HH_Posted,
> minute(Posted) as MM_Posted,
> Name,
> Prayer
> from prayer
>
> Then access the access the fields by the name (DOM_Posted).
> $recSet = mysql_query($query);
> $row = mysql_fetch_assoc($recSet);
> Access individual field:
> $row['DOM_Posted'];
> $row['M_Posted'];
> etc....
>
> OR
> Use the php date (Don't know - haven't tried) functions to parse the
> required values out of the Posted field.
Or you can use the DATE_FORMAT() function in your query.
SELECT DATE_FORMAT(Posted,'%m/%d/%Y') as F_Posted FROM Prayer
Then you can echo $row['F_Posted'] and it'll already be in the correct
format. Check the manual for the correct usage of DATE_FORMAT() (The
MySQL manual.)
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/