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

前端 未结 1 1763
抹茶落季
抹茶落季 2021-02-05 13:08

They have the same 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(         


        
相关标签:
1条回答
  • 2021-02-05 13:22

    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.

    0 讨论(0)
提交回复
热议问题