Jump to content


Photo

How to display Timestamp in readbale format from MySQL


  • Please log in to reply
3 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 28 July 2006 - 09:55 AM

I have a timestamp field in my database and I call it to display the time the record was inserted but it reads backwards which I believe in the MySQL standard 2006-07-28 00:40:23

How can I format the timestamp so it reads something like Posted: Tue Apr 04, 2006 02:29

Here is the code I use the display the records

$q = mysql_query("SELECT * FROM `news` LIMIT $set_limit, $limit"); 
  if(!$q) die(mysql_error()); 
     $err = mysql_num_rows($q); 
       if($err == 0) die("No matches met your criteria."); 

//Results per page: **EDIT LINK PATH** 
echo("   
<a href=?page=newsitem&limit=10&amp;pagenum=1></a> 
<a href=?page=newsitem&limit=25&amp;pagenum=1></a> 
<a href=?page=newsitem&limit=50&amp;pagenum=1></a>"); 

//show data matching query: 
while($code = mysql_fetch_object($q)) {
     echo("<h3>".$code->title."</h3>");
     echo($code->time."<BR>");
     echo("<p">".$code->content."</p><BR>"); 
}


the timestamp is stored under the fieldname time
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 yarnold

yarnold
  • Members
  • PipPipPip
  • Advanced Member
  • 67 posts
  • LocationWorcester, England

Posted 28 July 2006 - 10:23 AM

You can use something like this:
[pre]
date('F j, Y', strtotime($Timestamp))[/pre]

Change the 'F j, Y' into the form you want - http://www.php.net/date
Edward Yarnold
PHP/MySQL/Javascript Programmer
http://www.twixcoding.com

#3 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 28 July 2006 - 11:21 AM

Where do I put this?

date('F j, Y', strtotime($Timestamp))
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 July 2006 - 11:24 AM

From looking at your code $code->time holds your timestamp. SO what you'll want to do is change:
echo($code->time."<BR>");
to:
$time = date('F j, Y', strtotime($code->time))
echo '<b>Posted: ' . $time . "</b><br>";





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users