Jump to content

Archived

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

jetpackmac

Date display problems

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!

Share this post


Link to post
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.


Share this post


Link to post
Share on other sites

[!--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!

Share this post


Link to post
Share on other sites

×

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.