RE: [PHP] Date-format
| From: | Chuck Payne | Date: | Wed, 18 Sep 2002 18:55:38 +0000 |
| Subject: | RE: [PHP] Date-format | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116786@lists.php.net to get a copy of this message | ||
I know everyone love to quote read the manual and forget that we[newbies]
are only asking here because we need help...so here you go...
You can do the following...
DATE_FORMAT IS THE MySQL Command
And let say you want to format your date as the following mm-dd-yy(US) or
dd-mm-yy(the rest of the world).
By the way this are format keys....
%m the month in numbers,
%d the days in numbers,
%y the year in number
%M spells out the month
%D gives the date with th, rd, nd all that
%Y gives all four numbers
So you do the following sql statement...
SELECT DATE_FORMAT(yourdate, '%m-%d-%y') as youwanttocallit FROM yourtable;
So in your php code you can do this from your MySQL statement...
$youwantcallit = $myrow[youwanttoit];
<? echo $youwanttocallit; ?>
Advance note
then if you don't want to show 00-00-00 you can do this...
if ($youwanttocallit == "00-00-00") {
$youwanttocallit = " ";
}
that way you don't have a bunch of 00-00-00 showing up.
I hope that helps, because that is what the maillisting is for and not to
always quote "Read the Book".
Chuck Payne
Magi Design and Support