Datetime comparison PHP/Mysql?

后端 未结 4 854
醉梦人生
醉梦人生 2021-02-10 05:07

I\'m trying to make something like this:

if (datetime - system date > 15 minutes) (false)

if (datetime - system date          


        
4条回答
  •  离开以前
    2021-02-10 06:00

    You have a solution for MYSQL in other answers, a good solution for PHP is:-

    $now = new \DateTime();
    $target = new \DateTime(getTimeStringFromDB());
    $minutes = ($target->getTimestamp() - $now->getTimestamp())/60;
    if($minutes < 15){
        // Do some stuff
    } else {
        //Do some other stuff
    }
    

提交回复
热议问题