Highcharts-从MS SQL到PHP的日期格式问题


Highcharts - Date format from MS SQL to PHP issue

我一直在使用php从MS SQL数据库中检索信息。一切都很好,我试着从表中检索日期和时间格式。

这是我一直在使用的php:

$tsql5a = "SELECT * FROM FactTime"; 
$stmt5a = sqlsrv_query( $conn, $tsql5a);
$data5a = "";
while( $row = sqlsrv_fetch_array( $stmt5a, SQLSRV_FETCH_NUMERIC)){
$data5a .= "$row[1],";
}
$data5a = substr($data5a,0,strlen($data5a)-1);

我从表中检索的日期格式是:

2014-10-01 00:59:00.000

我得到以下错误:

"可捕获的致命错误:DateTime类的对象无法转换为字符串"

我已经研究过类似的问题,他们建议转换为字符串,但我完全不确定如何将其添加到现有的php中。

有人能帮忙吗。

谢谢Rob

好的,我继续搜索,下面是答案!

$data5a .= date_format($row[1]," Y-m-d H:i:s,");

我需要向从mssql-db表中提取的数据行添加一个日期格式,所以这就是代码的完整部分。

$tsql5a = "SELECT * FROM FactTime"; 
$stmt5a = sqlsrv_query( $conn, $tsql5a);
$data5a = "";
while( $row = sqlsrv_fetch_array( $stmt5a, SQLSRV_FETCH_NUMERIC)){
$data5a .= date_format($row[1]," Y-m-d H:i:s,");    // I had to add a space before the Y and a comma after the s so the php would pass the right format to the chart
}
$data5a = substr($data5a,0,strlen($data5a)-1);      // This removes the last , from the array

我希望这能帮助其他有同样问题的人。

谢谢Rob