Jump to content

Recommended Posts

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&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>");
} [/code]

the timestamp is stored under the fieldname [b]time[/b]
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]
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.