在SQL Server中爆炸日期和字符串

时间:2014-04-20 15:05:52

标签: php sql sql-server explode sqlsrv

我已将我的数据库从mysql转换为SQL服务器,并致力于爆炸日期和时间。我收到错误:explode() expects parameter 2 to be string,这是代码:

while($r = sqlsrv_fetch_array  ($sth)) 
    {

        //$temp = array();
        // assumes dates are in the format "yyyy-MM-dd"

        $dateString = $r['date'];
        $dateArray = explode('-', $dateString);
        $year = $dateArray[0];
        $month = $dateArray[1] - 1; // subtract 1 to convert to javascript's 0-indexed months
        $day = $dateArray[2];

        var_dump($dateString);

        // assumes time is in the format "hh:mm:ss"
        $timeString = $r['time'];
        $timeArray = explode(':', $timeString);
        $hours = $timeArray[0];
        $minutes = $timeArray[1];
        $seconds = $timeArray[2];

        var_dump($timeString);

        $temp = array();
        $temp[] = array('v' => "Date($year, $month, $day, $hours, $minutes, $seconds)"); 
        $temp[] = array('v' => $r['Temperatur']);


        $rows[] = array('c' => $temp);

    } 

当我对变量$ dateString和$ timeString执行var_dump时,第一个显示dateString和第二个timeString(PS:在我的SQL服务器日期中保存为日期,时间保存为类型(0):< / p>

enter image description here

这是我对我的mysql数据库执行此操作的方式,这是正确的enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个:

explode(":", $r['time']->format("H:i:s"));