Jump to content

Help using date_format()


PattyB

Recommended Posts

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.

[code]
$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')"];  ?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/21213-help-using-date_format/
Share on other sites

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

then
[code]
echo $row['date'];
[/code]
Link to comment
https://forums.phpfreaks.com/topic/21213-help-using-date_format/#findComment-94313
Share on other sites

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.