我想在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