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
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>";

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.