Jump to content


Photo

Date display problems


  • Please log in to reply
2 replies to this topic

#1 jetpackmac

jetpackmac
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 04 February 2006 - 01:39 AM

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!

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 February 2006 - 02:52 AM

You should do the following:

$query_rsGetFestDir = "SELECT *, DATE_FORMAT(deadline,'%Y/%m/%d') AS formattedDeadline FROM festdir ORDER BY `feststart` ASC";

And then retrieve the pretty date as follows:

<?php echo $row_GetFestDead['formattedDeadline']; ?>

As a matter of habit, I rarely overwrite the actual DB value, in case I need to "put it back".

Hope that helps.



Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 jetpackmac

jetpackmac
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 04 February 2006 - 03:22 AM


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users