Forum Moderators: coopster

Message Too Old, No Replies

Timestamp Formatting

Can anyone help with formatting the timestamp?

         

m4tt

7:46 am on Nov 13, 2005 (gmt 0)

10+ Year Member



Hi

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++;
}
?>

Anyango

8:04 am on Nov 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Although there are other options too but first check for this one, looks like you have a mistake in the code, i think that would be it.

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?

m4tt

9:00 am on Nov 13, 2005 (gmt 0)

10+ Year Member



Thank you! That worked perfectly. Always the simple things..