原版的:
$sql = "SELECT DATE(TimeAdded) AS Date, $column_name FROM Codes ORDER BY TimeAdded ASC";
已更改:
$sql = "SELECT DATE("m", TimeAdded ) AS Date, ColumnName FROM TableName ORDER BY TimeAdded ASC";
TimeAdded是使用NOW()添加的,基本上,我试图将其添加几个月。我在这里遇到的问题是报价单弄乱了。我尝试使用\摆脱它,但没有好处。还尝试了这个:
mysql_real_escape_string( DATE("m", TimeAdded ) )
更多信息:http://php.net/manual/en/function.date.php日期函数使用m来格式化月份。我认为这是PHP的功能。
更新:我将php的data()与mysql混合在一起,也就不足为奇了!
最佳答案
如何在MySQL中使用MONTH函数?
$sql = "SELECT MONTH(TimeAdded) AS `Date`, `ColumnName` FROM `TableName` ORDER BY `TimeAdded` ASC";
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_month