ddonaldson
10-09-2007, 12:27 PM
I work for a hospital and we are moving into a new building. The employees want me to put a simple countdown "ticker" on our intranet. The move is in a few months. Any one know code to create a date countdown?
Pegasus
10-09-2007, 01:08 PM
You can't do it with HTML, but what about something like this:
http://www.a1javascripts.com/time_related/countdownscript1/countdownscript1.html
Peg
coothead
10-09-2007, 01:17 PM
Hi there ddonaldson,
here is an example, that may suit your requirements...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>countdown to Armageddon</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
background-color:#003;
color:#fff;
}
#container {
text-align:center;
margin-top:100px;
}
#box {
width:760px;
background-color:#003;
font-family:verdana,sans-serif;
font-size:18px;
color:#fff;
text-align:center;
border:0 solid;
}
</style>
<script type="text/javascript">
/**********************These are the editable values***********************************/
var yr=2007; /*year value*/
var mo=12; /*month value*/
var da=9; /*day value*/
var hr=0; /*hours value*/
var mn=0; /*minutes value*/
var sc=0; /*seconds value*/
var ltr='the day of departure.'; /*event value*/
var msg='Are you still here?'; /*message for event value*/
var afr='That event has already passed'; /*message for after event value*/
/*************************************************************************************/
var mos=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var dys=(60*60*1000*24);
var hrs=(60*60*1000);
var mns=(60*1000);
function countdown(){
obj=document.getElementById('box');
now=new Date();
nwy=now.getUTCFullYear();
nwm=now.getMonth();
nwd=now.getDate();
nwh=now.getHours();
nwmn=now.getMinutes();
nws=now.getSeconds();
nwstr=mos[nwm]+' '+nwd+', '+nwy+' '+nwh+':'+nwmn+':'+nws;
ltrstr=mos[mo-1]+' '+da+', '+yr+' '+hr+':'+mn+':'+sc;
dd=Date.parse(ltrstr)-Date.parse(nwstr);
ddy=Math.floor(dd/dys*1);
dhr=Math.floor((dd%dys)/hrs*1);
dmn=Math.floor(((dd%dys)%hrs)/mns*1);
dsc=Math.floor((((dd%dys)%hrs)%mns)/1000*1);
if((ddy<=0)&&(dhr<=0)&&(dmn<=0)&&(dsc<=1)&&(nws==sc)){
obj.value=msg;
return;
}
else {
if(dsc<=-1) {
obj.value=afr;
return;
}
else {
obj.value=ddy+' days, '+dhr+' hours, '+dmn+' minutes, and '+dsc+' seconds left until '+ltr;
}
setTimeout('countdown()',1000);
}
}
onload=countdown;
</script>
</head>
<body>
<div id="container">
<input id="box" type="text"/>
</div>
</body>
</html>
At present the script is set to December 9th, 2007.
You should find it quite easy to edit the dates and messages. :agree:
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.