ryanwood4 Posted August 4, 2009 Share Posted August 4, 2009 Hi, I'm trying to display the date an article was published. They are saved to a database, with the date stored as a 'timestamp' under the column: 'article_timestamp' but I want the date displayed in a readable format such as 'DD-MM-YY 00:00:00' I have created the code so far which calls the article titles, and put them in a list, but am having trouble with the dates. This is the page so far: http://www.f1times.co.uk/archive.php <?php $con = mysql_connect("localhost","xxxx","xxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("f1times_articles", $con); $result = mysql_query("SELECT * FROM n2s_article ORDER BY article_id DESC LIMIT 21,35"); echo "<table border='0'> <tr> <th></th> </tr>"; while($row = mysql_fetch_array($result)) { $url = $row['article_url'] . "-" . $row['article_id'] . ".html"; echo "<tr>"; echo "<td><h5><a href='$url'>".stripslashes($row['article_title'])."</h5></a></td>"; } mysql_close($con); ?> I really have no clue where to go from here, everything I have tried hasn't worked, any help is greatly appreciated. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/168853-solved-displaying-the-date-using-a-timestamp/ Share on other sites More sharing options...
MatthewJ Posted August 4, 2009 Share Posted August 4, 2009 <?php $con = mysql_connect("localhost","xxxx","xxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("f1times_articles", $con); $result = mysql_query("SELECT * FROM n2s_article ORDER BY article_id DESC LIMIT 21,35"); echo "<table border='0'> <tr> <th></th> </tr>"; while($row = mysql_fetch_array($result)) { $url = $row['article_url'] . "-" . $row['article_id'] . ".html"; echo "<tr>"; echo "<td><h5><a href='$url'>".stripslashes($row['article_title'])."</h5></a></td>"; echo "<td>".date('d-m-Y g:i:s', $row['article_timestamp'])."</td>"; echo "</tr>"; } mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/168853-solved-displaying-the-date-using-a-timestamp/#findComment-890900 Share on other sites More sharing options...
ryanwood4 Posted August 4, 2009 Author Share Posted August 4, 2009 Thanks, now I know where I was going wrong! Link to comment https://forums.phpfreaks.com/topic/168853-solved-displaying-the-date-using-a-timestamp/#findComment-890923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.