我想在PHP上減去另一個日期,創建一個8小時的新日期(08:00:00)並從前一個結果中減去它。減去數據php
我使用TIMEDIFF減去前兩個日期,然後將DateTime轉換爲日期格式。
然後我用date_create創建了8小時的日期,以便從前面的結果中減去。
的問題是,當我用TIMEDIFF製作,去年計算,它返回我下面的消息:
Catchable fatal error: Object of class DateTime could not be converted to string in /Users/renatoaraujo/Documents/wlib compartilhada/wlib/ponto/index.php on line 50
我在哪裏丟失的?
這是我的代碼:
$row = mysqli_query($con, "SELECT TIMEDIFF('".$ponto[0]."','".$ponto[1]."')");
$resultado = mysqli_fetch_array($row);
$datetime = new DateTime($resultado[0]);
$data = date_create('08:00:00');
$row2 = mysqli_query($con, "SELECT TIMEDIFF('".$resultado[0]."', '".$data."'");
$saldo_total = mysqli_fetch_array($row2);
'date_create()'? – 2014-10-30 14:01:06
另外,你實際上並沒有在任何地方使用'$ datetime'? – AlpineCoder 2014-10-30 14:02:35
AplineCoder,對不起,這是因爲我在發佈之前做了一些測試。最後一個查詢的正確性是「SELECT TIMEDIFF('」。$ datetime。「','。。$ data。」'「); – user3596108 2014-10-30 14:04:48