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."; } Link to comment https://forums.phpfreaks.com/topic/52982-solved-date-displaying-as-jan-1-1970/ 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(); Link to comment https://forums.phpfreaks.com/topic/52982-solved-date-displaying-as-jan-1-1970/#findComment-261695 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); Link to comment https://forums.phpfreaks.com/topic/52982-solved-date-displaying-as-jan-1-1970/#findComment-261698 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? Link to comment https://forums.phpfreaks.com/topic/52982-solved-date-displaying-as-jan-1-1970/#findComment-261704 Share on other sites More sharing options...
taith Posted May 25, 2007 Share Posted May 25, 2007 $datetime=time(); Link to comment https://forums.phpfreaks.com/topic/52982-solved-date-displaying-as-jan-1-1970/#findComment-261712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.