Forum Moderators: coopster
I have the following code that outputs my timestamp into this format:
20051112201435
I have read some other threads and tried those but it still didn't output right.
Could someone please assist? Thanks!
Code:
<?
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT *, DATE_format(date,'%d-%m-%Y / %H:%i') AS display_date FROM news";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$title=mysql_result($result,$i,"title");
$date=mysql_result($result,$i,"date");
$image=mysql_result($result,$i,"image");
$article=mysql_result($result,$i,"article");
?>
<div class="news_item">
<p>
<h3><? echo $title;?></h3>
<img class="floatright" src="/images/<? echo $image;?>" alt="" >
<p>
<strong>Date: <? echo $date;?></strong>
</p>
<? echo $article;?><br />
</p>
</div>
<?
$i++;
}
?>
as per your following query
$query = "SELECT *, DATE_format(date,'%d-%m-%Y / %H:%i') AS display_date FROM news";
the output from function DATE_FORMAT , i.e. the formatted date is being picked up as "display_date"
however in your code you are assigning value to $date variable as simple "date" field from your query
$date=mysql_result($result,$i,"date");
rather it should be
$date=mysql_result($result,$i,"display_date");
isn't it?