Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
How can i reduce the "Days" to 30 in this Countdown Timer pop-up?

I have made a countdown timer pop-up with the help of google using javascript code which is set to end after 100 days, I am not able to change it to 30 days after many tries. As I am new to javascript, please help and solve my problem, also I want to know the proper logic behind this.

This is what I tried (This results as 100 days and so on hour,min, sec)

window.addEventListener("load", function(){ setTimeout( function open(event){ document.querySelector(".popup").style.display = "block"; }, 2000 ) });

document.querySelector("#close").addEventListener("click", function(){ document.querySelector(".popup").style.display = "none"; });

const year = new Date().getFullYear(); const fourthOfJuly = new Date(year, 6, 4).getTime(); const fourthOfJulyNextYear = new Date(year + 1, 6, 4).getTime(); const month = new Date().getMonth(); // countdown let timer = setInterval(function () { // get today's date const today = new Date().getTime(); // get the difference let diff; if (month > 6) { diff = fourthOfJulyNextYear - today; } else { diff = fourthOfJuly - today; } // math let days = Math.floor(diff / (1000 * 60 * 60 * 24)); let hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); let minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); let seconds = Math.floor((diff % (1000 * 60)) / 1000); // display document.getElementById("timer").innerHTML = ' \ ' + days + 'days \ \ ' + hours + 'hours \ \ ' + minutes + 'minutes \ \ ' + seconds + "seconds \ "; }, 1000);

I want it to show 30 days, but how?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

your code shows a countdown to the next 4th of July.

Do you want to display a countdown to a specific date or just always 30 days?

In your interval (that runs approximately each second) you compare the target date with the current date and then calculate your days, hours, minutes.

const today = new Date()

// targetDate = today + 30 days
const targetDate = new Date();
targetDate.setDate(targetDate.getDate() + 30);

const diff = targetDate.getTime() - today.getTime()

Here you can find a working version: https://jsfiddle.net/6bhuywn4/26/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!