How can I compare two dates in PHP?

前端 未结 13 2021
一整个雨季
一整个雨季 2020-11-22 06:02

How can I compare two dates in PHP?

The date is stored in the database in the following format

2011-10-2

If I wanted to

13条回答
  •  情歌与酒
    2020-11-22 06:40

    $today = date('Y-m-d');//Y-m-d H:i:s
    $expireDate = new DateTime($row->expireDate);// From db 
    $date1=date_create($today);
    $date2=date_create($expireDate->format('Y-m-d'));
    $diff=date_diff($date1,$date2);
    
    //echo $timeDiff;
    if($diff->days >= 30){
        echo "Expired.";
    }else{
        echo "Not expired.";
    }
    

提交回复
热议问题