PHP Countdown Script
Simple php countdown script allows you to display the time remaining
for the given two dates.
Features
- This php script allows you to find difference between the given dates.
- Countdown clock script displays days, hours, minutes and seconds left
for the next event.
- Countdown script allows you to edit the date and time formats in code.
- Easy to use and responsive.
Preview
Downloads
<?php
error_reporting(0);
$date = "2017-8-30";
$time = "12:10:55";
$dtime = $date." ".$time;
$tz_object = new DateTimeZone('Asia/Kolkata');
$datetime = new DateTime();
$datetime->setTimezone($tz_object);
$yt= $datetime->format('Y');
$mt= $datetime->format('m');
$dt= $datetime->format('d');
$hours= $datetime->format('H');
$minutes= $datetime->format('i');
$seconds= $datetime->format('s');
$now = $yt."-".$mt."-".$dt." ".$hours.":".$minutes.":".$seconds;
function countdowntime($now,$dtime)
{
$time1 = strtotime($now);
$time2 = strtotime($dtime);
$diffdhg = $time2-$time1;
gmdate("d H:i:s",$diffdhg);
$days = $diffdhg / 86400;
$day_explode = explode(".", $days);
$d = $day_explode[0];
$hours = '.'.$day_explode[1].'';
$hour = $hours * 24;
$hourr = explode(".", $hour);
$h = $hourr[0];
$minute = '.'.$hourr[1].'';
$minutes = $minute * 60;
$minute = explode(".", $minutes);
$m = $minute[0];
$seconds = '.'.$minute[1].'';
$second = $seconds * 60;
$s = round($second);
return $d.":"."$h".":".$m.":".$s;
}
$remaining = countdowntime($now,$dtime);
$difference = explode(":", $remaining);
$d = $difference[0];
$h = $difference[1];
$m = $difference[2];
$s = $difference[3];
?>
<div id="strclock" style='font-weight:bold;font-size:1.2em;'></div>
<script>
var day = <?php echo $d; ?>;
var hour = <?php echo $h; ?>;
var min = <?php echo $m; ?>;
var sec = <?php echo $s; ?>;
function countdown()
{
sec--;
if (sec < 0){
min--;
sec = 59
}
if (min < 0){
hour--;
min = 59
}
if (hour < 0){
hour = 23
day--;
}
var pat = /^[0-9]{1}$/;
sec = (pat.test(sec) == true) ? '0'+sec : sec;
min = (pat.test(min) == true) ? '0'+min : min;
hour = (pat.test(hour) == true) ? '0'+hour : hour;
document.getElementById('strclock').innerHTML = day+":"+hour+":"+min+":"+sec;
if (hour=='00' && min=='00' && sec=='00' && day=='0' ) {
alert("Times Out!");
}
else{document.getElementById('strclock').innerHTML = day+" Days "+hour+" Hours "+min+" Minutes "+sec+" Seconds Left for (2017-8-30)";
SD=window.setTimeout("countdown()",1000);}
}
countdown();
</script>
<div align="center">
<a style="text-decoration: none; color: lightgray; font-size: 10px; text-align: center;" href="//www.hscripts.com">©h</a>
</div>
- Release Date - 31-08-2015
- Get free version without ©copyright link for just $10/-
- For customization of this script or any script development, mail to support@hscripts.com
Usage
- Copy and paste the above code to run the script.
- Here function countdowntime($now,$dtime) is used to find difference between two dates.
- Using this Countdown script we can calculate the date and time between two dates through online.
License
Related Scripts