date_diff() expects parameter 1 to be DateTimeInterface, string given

▼魔方 西西 提交于 2019-12-04 18:43:48

问题


i got this problem and i don't know what to do... they have thesame format

$date_expire = '2014-08-06 00:00:00';
$date1 = date("Y-m-d G:i:s");
$date2 = date_create($date_expire);

$diff = date_diff($date1, $date2); //this line makes error..

回答1:


Because you are passing string whereas date_diff expects datetime object,

$date_expire = '2014-08-06 00:00:00';    
$date = new DateTime($date_expire);
$now = new DateTime();

echo $date->diff($now)->format("%d days, %h hours and %i minuts");

DEMO.



来源:https://stackoverflow.com/questions/24608529/date-diff-expects-parameter-1-to-be-datetimeinterface-string-given

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!