Timing Event Help: Trying to create a Timer to countdown to a certain date.

I have managed to put a countdown to a certain date. Unfortunately, I have run into an issue. Every single time I open the webpage. The counter keeps on resetting. I'm not sure what the problem is, but here is the script I used with the span that shows the coundown.


var upgradeTime = 172801;
var seconds = upgradeTime;
function timer() {
var days = Math.floor(seconds/24/60/60);
var hoursLeft = Math.floor((seconds) - (days86400));
var hours = Math.floor(hoursLeft/3600);
var minutesLeft = Math.floor((hoursLeft) - (hours
var minutes = Math.floor(minutesLeft/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
document.getElementById('countdown').innerHTML = days + ":" + hours + ":" + minutes + ":" + remainingSeconds;
if (seconds == 0) {
document.getElementById('countdown').innerHTML = "Completed";
} else {
var countdownTimer = setInterval('timer()', 1000);


  • Of course it will be reset because you provide an arbitrary number of seconds ahead which never changes so each time you start the timer the end goal will move further and further. Correct thing to do would be to use specific end date and use the difference of time from now as your starting point.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion