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

Forum

 

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

By Zicky - 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 Zicky - 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

That's great Zick!  Thanks for sharing

Cheers,

Tim Forrest
Toledoh Enterprises
www.toledoh.com.au

Countdown to Event if date greater then NOW

Here's another version of the Countdown to Event if the date is greater than now, which uses jQuery and provides an active countdown without the need for the page to refresh. Hope anyone who needs this finds it useful. See the URL to download the files you'll need for the jQuery function.

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  // load viewer library
  $libraryPath = 'cmsBuilder/lib/viewer_functions.php';
  $dirsToCheck = array('/home/server/html/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
  
  // load records
  list($eventsRecords, $eventsMetaData) = getRecords(array(
    'tableName'   => 'events',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $eventsRecord = @$eventsRecords[0]; // get first record
?>

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Countdown to Event</title>

<style type="text/css">
#countdown {
font-family:"Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-style:italic;
font-weight:bold;
font-size:28px;
}
</style>

<script src="jquery.1.11.0.js" type="text/javascript"></script>
<script src="jquery.countdown.js" type="text/javascript">
// download jquery.countdown.js here: http://hilios.github.io/jQuery.countdown/
</script>

</head>
<body>

<div id="countdown"></div>
<div class="clear-both"></div>
<script type="text/javascript">
$("#countdown")
//.countdown("2015/01/01", function(event) {
.countdown("<?php echo $eventsRecord['date'] ?>", function(event) {
$(this).text(
event.strftime('%D days %H:%M:%S')
);
});
</script>
</body>
</html>

Cheers, Zicky