ShoeLace1291 Posted May 25, 2007 Share Posted May 25, 2007 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."; } Quote Link to comment Share on other sites More sharing options...
taith Posted May 25, 2007 Share Posted May 25, 2007 date()'s 2nd variable MUST be in unix timestamp form(time())... you'd need to strtotime() your preset time, then put it into date(); Quote Link to comment Share on other sites More sharing options...
Gmunky Posted May 25, 2007 Share Posted May 25, 2007 $year = substr($datetime,0,4); $month = substr($datetime,5,2); $day = substr($datetime,8,2); $datetime=mktime(0,0,0,$month,$day,$year); $datetime=date('M j, o',$datetime); Quote Link to comment Share on other sites More sharing options...
ShoeLace1291 Posted May 25, 2007 Author Share Posted May 25, 2007 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? Quote Link to comment Share on other sites More sharing options...
taith Posted May 25, 2007 Share Posted May 25, 2007 $datetime=time(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.