2014-04-20 32 views
-1

我已經將我的數據庫從mysql轉換爲SQL服務器並處理爆炸日期和時間。我得到的錯誤:explode() expects parameter 2 to be string,這是代碼:SQL服務器中的爆炸日期和字符串

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); 

    } 

當我這樣做的var_dump的變量$ dateString和$ TIMESTRING我得到的,第一個顯示dateString和第二TIMESTRING(PS:在我的SQL服務器日期保存日期和時間保存類型(0):

enter image description here

這是它的外觀,當我做到這一點對我的mysql數據庫,這是正確的enter image description here

+2

請編輯您的上一個問題,並添加新的信息,而不是再次創建一個相同的。 – hakre

+0

我編輯但沒有幫助:( – user3270211

回答

1

試試這一個:

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