【发布时间】:2016-06-08 11:27:06
【问题描述】:
我有问题,我是初学者 我有一个生日日期(格式为 Y-m-d) 我有实际的日期。
$date = $_POST["DatumJJJJ"]."-".$_POST["DatumMM"]."-".$_POST["DatumTT"];
$birthday = new DateTime($date);
$now = new DateTime(date("Y-m-d"));
$difference = $birthday->diff($now);
echo $difference;
现在,最后一行出现错误:
Catchable fatal error: Object of class DateInterval could not be converted to string
我该怎么办?我看到了其他类似的问题,但它们对我没有帮助!
【问题讨论】:
-
看看dateInterval对象php.net/manual/en/class.dateinterval.php的结构
-
这是因为
$difference是尝试$difference->format('%R%a days');的对象,更多细节请查看php.net/manual/en/datetime.diff.php
标签: php