Jump to content

[SOLVED] Date Displaying as Jan 1, 1970


ShoeLace1291

Recommended Posts

The table row in PMA says the date for that row is 2005-05-24, but the page is displaying it as Jan 1, 1970.  This is my code:

 

$news = mysql_query("SELECT newsID,posterID,headline,message,datetime FROM news ORDER BY newsID DESC LIMIT 5") or die("Unable to fetch news articles.");

$articles = mysql_num_rows($news);

if($articles != 0){

            while($fetch=mysql_fetch_array($news)){
                     $posterid=$fetch["posterID"];
                     $headline=$fetch["headline"];
                     $message=$fetch["message"];
                     $datetime=$fetch["datetime"];
                     $datetime=date('M j, o',$datetime);

              

                     $poster = mysql_query("SELECT username FROM users WHERE uid = $posterid") or die("Unable to find news author.");

             $newsinfo=mysql_fetch_array($poster);

                  $author=$newsinfo["username"];

                     echo "<b>$headline</b><br>$message<br><div align='right'>Posted by $author on $datetime</div>";

} 

} else {

       echo "There no news articles to display at this time.";

}

Link to comment
https://forums.phpfreaks.com/topic/52982-solved-date-displaying-as-jan-1-1970/
Share on other sites

Got it.  Used a much easier method than that, Gmunky.

 

I was wondering... How do I set the datetime row with a mysql_query? 

 

something like this:

 

mysql_query("INSERT INTO news(posterID,headline,message,datetime)
             values('$posterID', '$headline', '$message', '$datetime');

 

What value would $datetime be?

 

Archived

This topic is now archived and is closed to further replies.

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