superkingkong Posted April 12, 2009 Share Posted April 12, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153704-solved-date_format-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2009 Share Posted April 12, 2009 There's nothing wrong with the syntax of your query. What's your code that outputs the results and what is your table definition? Quote Link to comment https://forums.phpfreaks.com/topic/153704-solved-date_format-help/#findComment-807862 Share on other sites More sharing options...
superkingkong Posted April 12, 2009 Author Share Posted April 12, 2009 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 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/153704-solved-date_format-help/#findComment-807920 Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2009 Share Posted April 12, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/153704-solved-date_format-help/#findComment-807930 Share on other sites More sharing options...
superkingkong Posted April 12, 2009 Author Share Posted April 12, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153704-solved-date_format-help/#findComment-807937 Share on other sites More sharing options...
fenway Posted April 14, 2009 Share Posted April 14, 2009 btw, how do i know when do i need to use alias or like the one above ? Basically any time you use an expression. Quote Link to comment https://forums.phpfreaks.com/topic/153704-solved-date_format-help/#findComment-810110 Share on other sites More sharing options...
superkingkong Posted April 15, 2009 Author Share Posted April 15, 2009 btw, how do i know when do i need to use alias or like the one above ? Basically any time you use an expression. thank you for the info Quote Link to comment https://forums.phpfreaks.com/topic/153704-solved-date_format-help/#findComment-810323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.