Jump to content


Photo

Help using date_format()


  • Please log in to reply
1 reply to this topic

#1 PattyB

PattyB
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 September 2006 - 11:48 PM

Hi,

I have the following code using date_format but it does not return anything.  Am I using this right
or is there a problem somewhere else?  If I have just date it returns the value fine.

$newsquery = "SELECT id, author, title, article, date 
FROM news order by date DESC LIMIT 0, 3";
$newsresult = mysql_query($newsquery);

while($row=mysql_fetch_array($newsresult)) 
{
?>
<tr width=100%>
<td width="40%" align="left">
<?php echo $row["date_format(date, '%m-%d-%Y')"];  ?>


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 18 September 2006 - 11:56 PM

date_format is a SQL function an so needs to go in the query.
$newsquery = "SELECT id, author, title, article, date_format(date, '%m-%d-%Y') as date
FROM news order by date DESC LIMIT 0, 3";

then
echo $row['date'];

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users