PHP - Conditional show/hide data by date

0 votes
304 views
added Nov 8, 2019 in PHP by lcjr First Warrant Officer (11,850 points)
// Show notification and ends by date
<?php
  $today     = date('c');
  $startdate = date('c', mktime(0,0,0,9,12,2017)); // Example: Hour, Minute, Second, Month, Day, Year
  $enddate   = date('c', mktime(23,59,59,9,30,2017));
  if ($today >= $startdate && $today < $enddate):
    echo '<div class="notify-top-wrapper">LC Marshal known as LC</div>';
    echo '<style>.notify-top .header{top:2.8rem}.notify-top-wrapper{display:none;width:100%;background-color:#f4b124;color:#252525;font-family:"Arial",sans-serif;font-weight:600;text-align:center;line-height:2.8rem;position:fixed;top:0;left:0;z-index:100;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}.notify-top .notify-top-wrapper{display:block}@media (max-width:1024px){.notify-top{padding-top:7.8rem}.notify-top .header-nav{top:7.8rem;height:calc(100% - 7.8rem)}.notify-top-wrapper{font-size:1.3rem}}@media (min-width:1025px){.notify-top{padding-top:10rem}.notify-top .front-wrapper .hero{top:10rem;height:calc(100vh - 10rem)}.notify-top .front-wrapper .hero.sticky{margin-top:2.8rem}}</style>';
    echo '<script type="text/javascript">(function($){$(document).ready(function(){$("body").addClass("notify-top");});})(jQuery);</script>';
  endif;
?>

 

1 Response

0 votes
responded Nov 8, 2019 by lcjr First Warrant Officer (11,850 points)
//Show condition by date
<div class="search-header">
  <?php
  $display   = false;
  // $tzget     = date_default_timezone_get();
  $today     = date('c');
  $startdate = date('c', mktime(0,0,0,10,18,2017)); // Example: Hour, Minute, Second, Month, Day, Year
  $enddate   = date('c', mktime(23,59,59,10,18,2017));
  if ($today >= $startdate && $today < $enddate)
    $display = true;
  if ($display):
    // Event: Change as you wish
    echo '<h3 class="m-t-0">Im on the run now</h3>';
  else:
    // Default Text
    echo '<h3 class="m-t-0">Imma part time explorer</h3>';
  endif;
  ?> 
</div>

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...