2014-10-20 48 views
0

我一直在使用PHP从MS SQL数据库中检索信息。我试图从表格中检索日期和时间格式。Highcharts - 从MS SQL到PHP的日期格式问题

这是我一直在使用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。

任何人都可以帮忙。

感谢 罗布

回答

0

好吧,我继续寻找,这里是答案!

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

我需要一个日期,甲酸添加到数据我是从MSSQL数据库表拉动的行,所以这是代码的完整部分的样子。

$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