Solved

Countdown to next friday

Posted on 2006-07-16
3
513 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide Table in merge 3 34
Google Analytics setup 5 51
Implement a function similar to grep in vanilla Javascript 3 21
Why is initialize not a function? 8 25
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

821 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