Re: Date Formatting Question
| From: | El Bekko | Date: | Wed, 14 Dec 2005 14:52:31 +0000 |
| Subject: | Re: Date Formatting Question | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-40867@lists.php.net to get a copy of this message | ||
Bomgardner, Mark A wrote:
I am trying to format the month portion of a date that I am trying to pull from MySQL to be placed into a drop down menu to modify the date. I have tried several ways and none seem to be working. I am pulling the date out of MySQL with: $sDate = explode("-", $row_events['Sdate']); And then attempting to insert each portion of the array into a drop down menu with: echo "<select name=Smonth>"; echo "<option selected>$sDate[1]</option>"; which is where I am running into the problem. I pull out the month as 2 digit numeric 01, 02, 03 etc., but I want it displayed as January, February, March, etc., I have tried the following with no success: Date("F",strtotime($sDate)); Strftime("%B:,$sDate); Date("F",$sDate); I would use MySQL to format the date, but I have three date fields to modify and it would be easier to do it in PHP Any pointers would be appreciated. Mark Bomgardner Technology Specialist KLETCmake a function like this: function datenum2str($date) { $newdate = str_replace("01","Jan",$date); $newdate = str_replace("02","Feb",$date); $newdate = str_replace("03","Mar",$date); $newdate = str_replace("04","Apr",$date); $newdate = str_replace("05","May",$date); $newdate = str_replace("06","Jun",$date); $newdate = str_replace("07","Jul",$date); $newdate = str_replace("08","Aug",$date); $newdate = str_replace("09","Sep",$date); $newdate = str_replace("10","Oct",$date); $newdate = str_replace("11","Nov",$date); $newdate = str_replace("12","Dec",$date); return $newdate; } And then use this: echo "<select name=Smonth>"; echo "<option selected value=\"$sDate[1]\">$newdate</option>"; Hope it helps, El Bekko