php $ diff->格式的问题

时间:2016-04-19 16:49:58

标签: php intervals

我使用以下代码获得"Fatal error: Call to a member function format() on a non-object in /home/mrbits/public_html/tickets/index2.php on line 407"

Xxx
Xxxx
xxxx
..
$t_enter=$row['fecha_ing'];   <- fields is type DATE
$yesterday=strtotime($t_enter);
$today_is = date("Y/m/d");
$diff=date_diff($yesterday,$today_is);
$t_elapsed= $diff->format("%y A %m m %d d");     <--- HERE's the ERROR
?>

<td><?php echo $t_idticket; ?></td>
<td><?php echo $t_elapsed; ?></td>

有什么不对?表格日期中的变量类型?

2 个答案:

答案 0 :(得分:0)

您的类型不匹配。 $yesterday是整数,$today_is是字符串。您必须执行strtotime($today_is);,因为$date_diff();需要2 DateTime个对象,因此您需要额外转换。

答案 1 :(得分:0)

使用this answer

$t_enter=$row['fecha_ing'];  
$yesterday=date_create($t_enter);
$today_is = date_create(date("Y/m/d"));
$diff=date_diff($yesterday,$today_is);
$t_elapsed= $diff->format("%y A %m m %d d");