Solved

Countdown to next friday

Posted on 2006-07-16
3
500 Views
Last Modified: 2006-11-18
Hi,
   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.

Thanks
0
Comment
Question by:cobybenson
3 Comments
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 500 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>";
}
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now