if date greater then NOW - countdown

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 22, 2014   (RSS)

By Mikey - September 9, 2014 - edited: September 9, 2014

Anyone have a suggestion on how to get this if statement working, so if the date is greater than the NOW (present) then the code within is shown, otherwise if the date is less than NOW (present) it is not displayed.

<!-- countdown -->
<?php if ($eventsRecord['date'] > 'NOW()'): ?>
<?php
$date = strtotime($eventsRecord['date']);
$remaining = $date - time();

$days_remaining = floor($remaining / 86400);
$hours_remaining = floor(($remaining % 86400) / 3600);
echo "<h5 style='color:#CC0000'>There are $days_remaining days and $hours_remaining hours remaining.</h5>";
?>
<?php endif ?>
<!-- /countdown -->

Thanks for any guidance,

Zick

if date greater then NOW

By Mikey - September 9, 2014 - edited: September 9, 2014

I got this worked out with some help from this thread (http://www.interactivetools.com/forum/forum-posts.php?postNum=2213467#post2213467) for anyone who may find this useful.

<!-- countdown -->
<?php
$currentDateTime = strtotime(date("Y-m-d H:i:s"));
$theEventDate = strtotime($eventsRecord['date']);
?>
<?php if ($theEventDate > $currentDateTime): ?>

<?php
$date = strtotime($eventsRecord['date']);
$remaining = $date - time();

$days_remaining = floor($remaining / 86400);
$hours_remaining = floor(($remaining % 86400) / 3600);
$minutes_remaining = floor(($remaining % 3600) / 60);
//$seconds_remaining = ($remaining % 60);
echo "<h5 style='color:#CC0000'>There are $days_remaining days, $hours_remaining hours and $minutes_remaining minutes remaining.</h5>";

?>
<?php endif ?>
<!-- /countdown -->

Zick

if date greater then NOW

By Toledoh - September 11, 2014

That's great Zick!  Thanks for sharing

Cheers,

Tim (toledoh.com.au)