[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Countdown to next friday

Posted on 2006-07-16
3
Medium Priority
?
530 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
[X]
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
3 Comments
 
LVL 16

Accepted Solution

by:
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>";
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

650 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