Countdown to next friday

Posted on 2006-07-16
Medium Priority
Last Modified: 2006-11-18
   I'd like to create a countdown timer that shows the number of days, hours, minutes and seconds till the next Friday. Is it possible to do this with javascript?

I imagine the only difficulty could be finding the date of the next Friday, but I could add this to a PHP variable if it helps.

Any help would be appreciated.

Question by:cobybenson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Accepted Solution

Peter Kwan earned 2000 total points
ID: 17117082
Here is the script:

function countdownNextFriday() {
      var today = new Date();
      var todayOfWeek = today.getDay();
      var daysToNextFriday = (todayOfWeek >= 5?12:5) - todayOfWeek;

      var nextFriday = new Date(today.getTime() + (daysToNextFriday * 86400000));
      nextFriday.setHours(0); nextFriday.setMinutes(0); nextFriday.setSeconds(0); nextFriday.setMilliseconds(0);

      var diff = nextFriday.getTime() - today.getTime();      
      countdown.innerHTML =
      "<p> Countdown to Next Friday: " +
      Math.floor(diff/(24 * 60 * 60 * 1000)) + " days " +
      Math.floor(diff/(60 * 60 * 1000) % 24) + " hours " +
      Math.floor(diff/(60 * 1000) % 60) + " minutes " +
      Math.floor(diff/1000 % 60) + " seconds "
       + "</p>";

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question