【问题标题】:Highcharts - Date format from MS SQL to PHP issueHighcharts - 从 MS SQL 到 PHP 问题的日期格式
【发布时间】:2014-10-20 16:05:38
【问题描述】:

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

谁能帮忙。

谢谢 抢

【问题讨论】:

    标签: php datetime highcharts


    【解决方案1】:

    好的,我继续搜索,这就是答案!

    $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
    

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

    谢谢 抢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多