[PHP-DB] Date formatting question
I need to reformat the output of the 'dates' field from '2009-04-08' to 'Wed. Apr. 8th'. Any help would be appreciated. Thanks. --- for ($counter = 0; $counter mysql_num_rows($resultID); $counter++); while ($row = mysql_fetch_object($resultID)) { print tr; print td . $row-dates . /td; print td . $row-times . /td; print td . $row-am_pm . /td; print td . $row-height . /td; print td . $row-cond . /td; print /tr; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Date formatting question
Jack Lauman wrote: I need to reformat the output of the 'dates' field from '2009-04-08' to 'Wed. Apr. 8th'. Any help would be appreciated. You can either do it using mysql date formats (see http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format) or something like date('...', strtotime($result-date)); See http://php.net/date and http://php.net/strtotime -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Date formatting question
See the date function Http://www.php.net/date Bastien Sent from my iPod On Apr 8, 2009, at 21:41, Jack Lauman jlau...@nwcascades.com wrote: I need to reformat the output of the 'dates' field from '2009-04-08' to 'Wed. Apr. 8th'. Any help would be appreciated. Thanks. --- for ($counter = 0; $counter mysql_num_rows($resultID); $counter++); while ($row = mysql_fetch_object($resultID)) { print tr; print td . $row-dates . /td; print td . $row-times . /td; print td . $row-am_pm . /td; print td . $row-height . /td; print td . $row-cond . /td; print /tr; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Date Formatting Question
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 KLETC -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Date Formatting Question
You got the right idea, but you're making it more complicated than it needs to be. your $sDate after using explode() is going to contain an array. strtotime doesn't take an array, it takes a string. $monthName = date(F, strtotime($row_events['Sdate'])); $monthNumber = date(m, strtotime($row_events['Sdate'])); // or n if you want 1 instead of 01 for January echo select name='sMonth'\n; for ($i = 1; $i = 12; $i++) // using date() below to get month name, day and year irrelevant $selectMonthText = date(F, mktime(0, 0, 0, $i, 1, 2000)); if ($i == $monthNumber) $selected = SELECTED; else $selected = ; echo option value='$i'$selected$selectMonthText/option\n; echo /select\n; -TG = = = Original message = = = 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 KLETC ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php