我在数据库中有一个日期,我想将它与当前日期进行比较。所以我写了以下函数:
$today = new DateTime();
$today_date = $current_date->format('Y-m-d H:i:s');
function do_diifernce($date_1, $date_2) {
$my_date = $date_1;
$createDate = new DateTime($my_date);
$strip = $createDate->format('Y-m-d');
$difference = $date_2->diff($createDate, true);
$difference->total_difference = $difference->y . "." . $difference->m;
return $difference;
}
$comparison = do_diifernce($databse_date, $today_date);
所以
$databse_date = 2019-06-01 00:00:00.000000
$today_date = 2019-05-06 10:48:01
但我无法打印$comparison.
PHP 致命错误:未捕获的错误:调用字符串上的成员函数 diff()
我该如何解决?
阿波罗的战车