Your whole code can be reduced to this. /* secsToDHMS() * Author Gary Green * http://stackoverflow.com/users/63523/gary-green */ function secsToDHMS(s) { var x = [86400, 3600, 60, 1],z,i=-1; while (z=x[++i]) x[i] = ("0" + parseInt(s / z,10)).slice(-2), s %= z; return x.join(':'); }; (function() { var currentDate = new Date(); var endDate = new Date('March 23, 2012 22:42:30'); var secsToGo = (new Date(endDate - currentDate)).getTime() / 1000; var countdownElement = document.getElementById('countdown'); var timer = setInterval(function() { if (--secsToGo < 0) { clearInterval(timer); return; } countdownElement.innerHTML = secsToDHMS(secsToGo); }, 1000); })(); **Fiddle**: http://jsfiddle.net/xg63V/3