$SQLString = "SELECT
count(score) as counts,
score, month,
date FROM persons
GROUP BY day, month, year
ORDER BY date asc";
$result = mysql_query($SQLString);
$num = mysql_num_rows($result);
$data[0] = array('day','counts');
for ($i=1; $i<($num+1); $i++)
{
$data[$i] = array(substr(mysql_result($result, $i-1, "date"), 0, 10),
(int) mysql_result($result, $i-1, "counts"));
}
echo json_encode($data);
这个输出是这样的:PHP数组与日期
[["day","counts"],["2012-01-20",1],["2012-02-06",1],["2012-11-16",2],["2013-04-13",1]]
我的问题是,我需要在日期类型,而不是字符串,日期值(如“2012-01-20”)。
我真的需要你的帮助...
使用'http://www.php.net/manual/en/datetime.createfromformat .php'和'http:// www.php.net/manual/en/datetime.format.php' –
你可以通过MYSQL或http://php.net/manual/en/function.strtotime.php –