[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 532
  • Last Modified:

Countdown to next friday

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
cobybenson
Asked:
cobybenson
1 Solution
 
Peter KwanCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now