2

I've got a countdown timer that shows one thing before 2pm and another for after 2pm. I need to now add something else that shows something else on the weekend and hides the first part. Here is what I have so far:

<?php if ($_product->getAttributeText('select_program') == "Yes"): ?> 

    <?php date_default_timezone_set('America/New_York'); ?>
<div id="countdown">
    <?php

    /* This sets the $time variable to the current hour in the 24 hour clock format */
    $time = date("H");
    /* Set the $timezone variable to become the current timezone */
    $timezone = date("e");

    if ($time >= "8" && $time <= "14") {
        echo $this->getLayout()->createBlock('cms/block')->setBlockId('countdown-products')->toHtml();
    } else

    if ($time >= "15" && $time < "23") {
        echo $this->getLayout()->createBlock('cms/block')->setBlockId('countdown_tomorrow')->toHtml();
    } 
    ?>
</div>
<?php endif ?>



<div id="weekendchecker">
    <!--Check for Sat and Sun-->
<?php if ($_product->getAttributeText('cd_select_program') == "Yes"): ?> 
    <?php
    if(date('D') == 'Sat' || date('D') == 'Sun') { 
      echo $this->getLayout()->createBlock('cms/block')->setBlockId('countdownSatSun')->toHtml();
    } 
    ?>
<?php endif ?>
</div>

1 Answer 1

1
 <?php   
     date_default_timezone_set('America/New_York');
     echo $date= date('Y-m-d') ;
     $timestamp = strtotime($date);
     $weekday= date("l", $timestamp );
     $normalized_weekday = strtolower($weekday);
     if (($normalized_weekday == "saturday") || ($normalized_weekday == "sunday")) {
              echo $this->getLayout()->createBlock('cms/block')->setBlockId('countdownSatSun')->toHtml();

    } 
5
  • Thank you. How can I hide the top part when this code is rendered on the weekend? Aug 20, 2018 at 15:46
  • Please disregard. I got it. Thank you very much for your help. I just added else if and declared a new variable for hours. Aug 20, 2018 at 15:51
  • Glad could help!
    – Gagan
    Aug 21, 2018 at 5:00
  • Within those blocks are javascript countdown timers. Is there a simple way to make it stay on Eastern Standard time? I know the PHP will. Aug 21, 2018 at 16:08
  • I am not confident that I got your point. But as per my understanding you want to set timezone to EST via javascript. Possible solution - stackoverflow.com/questions/36206260/…
    – Gagan
    Aug 22, 2018 at 4:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.