Login | Sign up | Toll-Free: 1-800-752-0455
 
 

Forum

 

1 posts by 1 authors in: Forums > CMS Builder Community
Last Post: September 22, 2014

Here's PHP powered Countdown to Event if the date is greater than now, which counts down the days, hours and minutes until the event date. This solution requires the page to be refreshed to show the most current count down time. Hope anyone who needs this finds it useful.

  // load records
  list($eventsRecords, $eventsMetaData) = getRecords(array(
    'tableName'   => 'events',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $eventsRecord = @$eventsRecords[0]; // get first record


<?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 ?>

Cheers, Zicky