countdown timer in php

countdown timer in php

 $dateFormat = "d F Y -- g:i a";
 $targetDate = $futureDate;//Change the 25 to however many minutes you want to countdown change date in strtotime
 $actualDate = $date1;
 $secondsDiff = $targetDate - $actualDate;
 $remainingDay = floor($secondsDiff/60/60/24);
 $remainingHour = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
 $remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
 $remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
 $actualDateDisplay = date($dateFormat,$actualDate);
 $targetDateDisplay = date($dateFormat,$targetDate);
 <script type="text/javascript">
 var days = <?php echo $remainingDay; ?>
 var hours = <?php echo $remainingHour; ?>
 var minutes = <?php echo $remainingMinutes; ?>
 var seconds = <?php echo $remainingSeconds; ?>
 function setCountDown(statusfun)
 {//alert(seconds);
 var SD;
 if(days >= 0 && minutes >= 0){
 var dataReturn = jQuery.ajax({
 type: "GET",
 url: "<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'index.php/countdowncont/'; ?>",
 async: true,
 success: function(data){
 var data = data.split("/");
 day = data[0];
 hours = data[1];
 minutes = data[2];
 seconds = data[3];
 }
 });
 seconds--;
 if (seconds < 0){
 minutes--;
 seconds = 59
 }
 if (minutes < 0){
 hours--;
 minutes = 59
 }
 if (hours < 0){
 days--;
 hours = 23
 }
 document.getElementById("remain").style.display = "block";
 document.getElementById("remain").innerHTML = " Your Product Reverse For "+minutes+" minutes, "+seconds+" seconds";
 SD=window.setTimeout( "setCountDown()", 1000 );
 }else{
 document.getElementById("remain").innerHTML = "";
 seconds = "00"; window.clearTimeout(SD);
 jQuery.ajax({
 type: "GET",
 url: "<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'index.php/countdown/'; ?>",
 async: false,
 success: function(html){
 }
 });
 document.getElementById("remain").innerHTML = "";
 window.location = document.URL; // Add your redirect url
 }
 }
 </script>
 <?php
 if($date1 < $futureDate && ($qtyCart > 0)){ ?>
 <script type="text/javascript">
 setCountDown();
 </script>
 <?php }else{ ?>
 <style>
 #remain{display:none;}
 </style>
 <?php }}?>
 <div id="remain"></div>

You may also like...

Creating a Shopify App using Laravel How to Create Custom WordPress Plugin? How to Build a Telegram Bot using PHP How to Convert Magento 2 into PWA?