AdRock Posted July 28, 2006 Share Posted July 28, 2006 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 [b]2006-07-28 00:40:23[/b]How can I format the timestamp so it reads something like [b]Posted: Tue Apr 04, 2006 02:29 [/b]Here is the code I use the display the records[code]$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&pagenum=1></a> <a href=?page=newsitem&limit=25&pagenum=1></a> <a href=?page=newsitem&limit=50&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>"); } [/code] the timestamp is stored under the fieldname [b]time[/b] Link to comment https://forums.phpfreaks.com/topic/15869-how-to-display-timestamp-in-readbale-format-from-mysql/ Share on other sites More sharing options...
yarnold Posted July 28, 2006 Share Posted July 28, 2006 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 Link to comment https://forums.phpfreaks.com/topic/15869-how-to-display-timestamp-in-readbale-format-from-mysql/#findComment-65081 Share on other sites More sharing options...
AdRock Posted July 28, 2006 Author Share Posted July 28, 2006 Where do I put this?date('F j, Y', strtotime($Timestamp)) Link to comment https://forums.phpfreaks.com/topic/15869-how-to-display-timestamp-in-readbale-format-from-mysql/#findComment-65095 Share on other sites More sharing options...
wildteen88 Posted July 28, 2006 Share Posted July 28, 2006 From looking at your code $code->time holds your timestamp. SO what you'll want to do is change:[code]echo($code->time."<BR>");[/code]to:[code]$time = date('F j, Y', strtotime($code->time))echo '<b>Posted: ' . $time . "</b><br>";[/code] Link to comment https://forums.phpfreaks.com/topic/15869-how-to-display-timestamp-in-readbale-format-from-mysql/#findComment-65097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.