jetpackmac Posted February 4, 2006 Share Posted February 4, 2006 Hey everyone!I have a MySQL database setup on my webserver and I am displaying the contents of that db on a webpage. I have a date column in the db... of course it displays the date as yyyy/mm/dd. I am trying to change the display on my webpage to look like mm/dd/yyyy. Does anyone know how to do this?I looked up the DATE_FORMAT() function but I dont think I was using it right...I setup a record set to retrieve the db:[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]<?php require_once('../Connections/GetFestDir.php'); ?><?phpmysql_select_db($database_GetFestDir, $GetFestDir);$query_rsGetFestDir = "SELECT * FROM festdir ORDER BY `feststart` ASC";$rsGetFestDir = mysql_query($query_rsGetFestDir, $GetFestDir) or die(mysql_error());$row_rsGetFestDir = mysql_fetch_assoc($rsGetFestDir);$totalRows_rsGetFestDir = mysql_num_rows($rsGetFestDir);?>[!--colorc--][/span][!--/colorc--]Then I use php to display the date like this:[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]<?php echo $row_GetFestDead['deadline']; ?>[!--colorc--][/span][!--/colorc--]So do I change the date format when I retrieve the db (in the SELECT area)? or do I change it in the php that displays it?Any help is really appreciated! Thanks! Link to comment https://forums.phpfreaks.com/topic/3316-date-display-problems/ Share on other sites More sharing options...
fenway Posted February 4, 2006 Share Posted February 4, 2006 You should do the following:[code]$query_rsGetFestDir = "SELECT *, DATE_FORMAT(deadline,'%Y/%m/%d') AS formattedDeadline FROM festdir ORDER BY `feststart` ASC";[/code]And then retrieve the pretty date as follows:[code]<?php echo $row_GetFestDead['formattedDeadline']; ?>[/code]As a matter of habit, I rarely overwrite the actual DB value, in case I need to "put it back".Hope that helps. Link to comment https://forums.phpfreaks.com/topic/3316-date-display-problems/#findComment-11303 Share on other sites More sharing options...
jetpackmac Posted February 4, 2006 Author Share Posted February 4, 2006 [!--sizeo:6--][span style=\"font-size:24pt;line-height:100%\"][!--/sizeo--][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]YOU ROCK![!--colorc--][/span][!--/colorc--][!--sizec--][/span][!--/sizec--]Thanks so much! Link to comment https://forums.phpfreaks.com/topic/3316-date-display-problems/#findComment-11304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.