mardi 27 février 2018

If else statement for PHP DateTime diff

I am using meta_box value (YmdHi) and current Date&time to print time difference. And this code work for me.

Now additionally i want to print Live when 2 hours left to start Event.

What mistake I 'm doing to print if or else currently this not work for me?

$then = date( get_post_meta( get_the_ID(), '_start_eventtimestamp', true ) ) ;
$then = new DateTime($then);
$now = new DateTime();
$sinceThen = $then->diff($now);

if ($sinceThen > 2 * HOUR_IN_SECONDS){
       echo $sinceThen->d.'days'; 
       echo $sinceThen->h.'hours'; 
       echo $sinceThen->i.'minutes';
 }
else{
        echo 'LIVE';
 }

Aucun commentaire:

Enregistrer un commentaire