Jump to content

Date display problems


jetpackmac

Recommended Posts

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'); ?>
<?php
mysql_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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.