Search code examples
phpmysqllivecountdown

PHP/Javascript countdown script


Note * I want some one to fix it and tell me how they did it not tips on how to do it or coments about php nd java mixed in it *

I have a countdown script that is working, but when it hits the target date the timer keeps on going to a negative time. I want it to stop on that target date and just display a finishing message. It's live on my site. I just need help editing the countdown script.

I want to keep the same layout. I need some help adding the finishing message and stopping it from going into the negative date, or just make it not display the 0days, 0 hours, 0mins, 0sec until the site's officially released. When that finally happens, I want it to display a message.

countdown script

<?php date_default_timezone_set('EST'); ?>
<?php
// Define your target date here
    $targetYear  = 2011;
    $targetMonth = 9;
    $targetDay   = 1;
    $targetHour  = 20;
    $targetMinute= 00;
    $targetSecond= 00;
// End target date definition

// Define date format
$dateFormat = "Y-m-d H:i:s";

$targetDate = mktime($targetHour,$targetMinute,$targetSecond,$targetMonth,$targetDay,$targetYear);
$actualDate = time();

$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));

$targetDateDisplay = date($dateFormat,$targetDate);
$actualDateDisplay = date($dateFormat,$actualDate);

?>
<script type="text/javascript">
  var days = <?php echo $remainingDay; ?>  
  var hours = <?php echo $remainingHour; ?>  
  var minutes = <?php echo $remainingMinutes; ?>  
  var seconds = <?php echo $remainingSeconds; ?>  
</script>
<body onLoad="setCountDown();">
<center><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes and $remainingSeconds seconds";?> untill official release</center>

how its added on the site

<script type="text/javascript">
$(function() {
    /* Union War */
    $("#Countdown2").load("http://imperialism.zxq.net/includes/process/uwcountdown.php");

    setInterval(function(){
        $("#Countdown2").load("http://imperialism.zxq.net/includes/process/uwcountdown.php");
    }, 1000);
});
</script>

<div id="uwCD" class="uwCD">
    <div id="Countdown2"></div>
</div>

Solution

  • if($targetDate != $actualDate && $targetDate > $actualDate) { 
    echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes and $remainingSeconds seconds"; 
    } else { 
    echo "0 days, 0 hours, 0 minutes and 0 seconds"; 
    }