Jump to content

[SOLVED] Displaying the date using a Timestamp


ryanwood4

Recommended Posts

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.

<?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);
?>

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.