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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.