How can I compare two dates in PHP?

前端 未结 13 2253
一整个雨季
一整个雨季 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:54

    Here's a way on how to get the difference between two dates in minutes.

    // set dates
    $date_compare1= date("d-m-Y h:i:s a", strtotime($date1));
    // date now
    $date_compare2= date("d-m-Y h:i:s a", strtotime($date2));
    
    // calculate the difference
    $difference = strtotime($date_compare1) - strtotime($date_compare2);
    $difference_in_minutes = $difference / 60;
    
    echo $difference_in_minutes;
    

提交回复
热议问题