Countdown Script

MCSports's picture

He has: 11 posts

Joined: Dec 2005

I need help. I have the following script on my website. I am wanting to countdown to football kickoff on August 31, 2006 at 7pm. I have everything ready, but can't seem to get the hour to countdown to 7pm....it's wanting to countdown to midnight. Any ideas?

Here's the script:

var before="Kickoff!"
var current="Are You Ready For Some Football?"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[m-1]+" "+d+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday==0&&dhour==0&&dmin==0&&dsec==1){
document.forms.count.count2.value=current
return
}
else
document.forms.count.count2.value=""+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds until "+before
setTimeout("countdown(theyear,themonth,theday)",1000)
}
//enter the count down date using the format year/month/day
countdown(2006,08,31)
</script>[/B]

timjpriebe's picture

He has: 2,667 posts

Joined: Dec 2004

You haven't taken into account hours, minutes or seconds in futurestring.

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

You will likely need to add a 4th argument to function countdown (yr,m,d,h) the other alternative is to get the unix timestamp representation of the exact second (easily done with php's strtotime()) and then pass that as an argument.

&lt;script&gt;
var before="Kickoff!"
var current="Are You Ready For Some Football?"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(timestamp){
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000){
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
dd=timestamp-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday==0&&dhour==0&&dmin==0&&dsec==1){
document.forms.count.count2.value=current
return
}else{
document.forms.count.count2.value=""+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds until "+before
setTimeout("countdown(theyear,themonth,theday)",1000)
}
//enter the count down date using the format year/month/day
countdown(1157068800); // <?=strtotime('August 31, 2006 7pm');?>
&lt;/script&gt;
'

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.