Re: display formatted date??

From: Date: Mon, 26 Jun 2000 15:35:51 +0000
Subject: Re: display formatted date??
Groups: php.general 
Request: Send a blank email to php-general+get-3131@lists.php.net to get a copy of this message
>hi, > >i have a field "dated" of type DATETIME. now how to i format this into the format (dd-mon-yyyy). i tried the following code but i am not getting the reqd result >it always gives 01-Jan-1970. > >code.... > > <? $row = mysql_fetch_array($result) ?> > <tr><td valign=top><font color="#3300CC" size="2"> > <? $temp=$row["dated"]; > echo "value in MySQL = $temp"; > $arr1 = getdate($temp); You cannot use getdate() with a string variable; it requires a timestamp. Try this instead: $month=substr($temp,5,2); $day=substr($temp,8,2); $year=substr($temp,0,4); $timeStamp=mktime(0,0,0,$month,$day,$year); $formattedDate=date("d-M-Y",$timeStamp); echo "$formattedDate"; There may be a MySQL function that can format the date; I don't know. Regards, Carroll Barrett

« previous php.general (#3131) next »