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
我收到以下错误:
&p>Catchable致命错误:DateTime类的对象无法转换为字符串
我已经看过类似的问题,他们建议转换为字符串但是我并不确定如何将它添加到现有的PHP中。
任何人都可以帮助。
谢谢
Rob
好的,我继续搜索,这里是答案! b
$ b
$ data5a。= date_format($ row [1],Ymd 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); //我必须在Y之前添加一个空格和一个逗号,所以php将通过正确的格式到图表
}
$ data5a = substr($ data5a,0,strlen($ data5a)-1); //从数组中删除最后一个
我希望这将帮助其他人遇到同样的问题。
感谢
Rob
I've been using php to retrieve information from an MS SQL database. All been fine tile I tried to retrieve a date and time format from the table.
This is the php I've been using:
$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);
The date format I'm retrieving from the table is:
2014-10-01 00:59:00.000
I'm getting the following error:
"Catchable fatal error: Object of class DateTime could not be converted to string"
I've looked through similar issues and they suggest a conversion to a string but I'm not certain at all of how to add this into the existing php.
Can anyone help.
Thanks Rob
Okay, I continued to search and here is the answer!
$data5a .= date_format($row[1]," Y-m-d H:i:s,");
I needed to add a date formate to the row of data I was pulling from the mssql db table, so this is what the completed section of the code looks like.
$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
I hope this will help others with the same problem.
Thanks Rob
这篇关于Highcharts - 从MS SQL到PHP问题的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!