I am trying to pass a message if the set time has passed. I have two variables the $date1
which is the current time and the $date2
which is the target time. The third variable $interval
is the difference between the two times.
The challenge I am having is that I can't get the code to work when time has passed. It works properly if the target time $date2
is ahead of the current time $date1
.
date_default_timezone_set('Africa/Nairobi');
$date1 = new DateTime();
$date2 = new DateTime("$closing_date"); //Closing date 09-03-2021 13:00
$interval = $date1->diff($date2);
//PHP Code
add_filter('the_content', 'hide_post_contents');
function hide_post_contents( $content ) {
if(( $interval->h = 0 ) && ( $interval->i <=0 )) {
return '<h3>This content is no longer available</h3>
<p>Please feel free to check out other content.</p>';
}
return $content;
}
I noticed that even after the time has passed, the time passed is not treated as negative value. Thanks