Jump to content

[SOLVED] date_FORMAT() help


superkingkong

Recommended Posts

hi guys,

 

I'm trying to display the datetime field with a particular format, unfortunately it is not showing anything using the date_FORMAT () function. if i remove the date_FORMAT () function, it is displaying YYY-MM-DD HH:MM:SS

 

here is my select statement.

 

$result = mysql_query("SELECT id, referrer, DATE_FORMAT(datetime, '%W %M %Y'), ipaddress, hostname, page, useragent FROM weblog ORDER BY id DESC");

 

would appreciate if you can please help, thanks.

Link to comment
https://forums.phpfreaks.com/topic/153704-solved-date_format-help/
Share on other sites

There's nothing wrong with the syntax of your query. What's your code that outputs the results and what is your table definition?

 

 

hmm...  strange.

I'm using datetime as the datatype, and the field name is datetime :P

initially i was using timestamp, but changed it to datetime.

 

$result = mysql_query("SELECT id, referrer, DATE_FORMAT(datetime, '%W %M %Y'), timezone, ipaddress, hostname, page, useragent FROM weblog ORDER BY id DESC");
echo "<table border=2>";

while($row = mysql_fetch_array($result))
{

echo "<tr>";
echo '<td><a href="' . $row['referrer'] . '">Referrer</a> 22</td>';
echo "<td>" . $row['datetime'] . " (" . $row['timezone'] . ") 33</td>";
echo "<td>" . $row['page'] . " 44</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . long2ip($row['ipaddress']) . " </td>";
echo "<td>" . $row['hostname'] . " </td>";
echo "<td>" . $row['useragent'] . " </td>";
echo "</tr>";
}
echo "</table>";

 

The field name will be something like $row['DATE_FORMAT()']

 

You can either use an Alias name in the query or since you are using mysql_fetch_array, you could use $row[2]

 

thanks a lot :) i've learnt some thing new today :)

 

btw, how do i know when do i need to use alias or like the one above ?

 

thanks.

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.