php Object of class DateInterval could not be converted to string

送分小仙女□ 提交于 2019-11-26 17:23:06

问题


i've tried using date_diff and date_create to get a difference from two date that's already converted to string.

here's the code:

$date_1 = date_create();
$date_now = date_format($date_1, 'Y-m-d');


//echo $date_now . "\n";
$date=date_create($date_now);
date_add($date,date_interval_create_from_date_string("3 days"));
$date_return =  date_format($date,"Y-m-d");


$diff = date_diff(date_create($date_now), date_create($date_return));

echo $diff;

and i am getting this error:

Object of class DateInterval could not be converted to string

回答1:


You need to call DateInterval::format() to display that difference as a string.

echo $diff->format('%d days');

See the manual for all of the available formatting options.



来源:https://stackoverflow.com/questions/28621270/php-object-of-class-dateinterval-could-not-be-converted-to-string

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