Hi. My name is Adam Saunders and I live in the world of 1's and 0's. This is my tiny contribution the vastness of internet information. It's just an opinion and should you have your own, please comment it!

22 Aug 2013

This will allow you to find the next weekday and time from another time (by default the current date). For example, this can be used to find the Date of the next Monday at 6:30am.

var d = new Date();
var nextD = 1; // Monday
var nextT = 390; // 6 hours 30 minutes
if (d.getDay() == nextD)
{
  if ((d.getHours() * 60 + d.getMinutes()) >= nextT)
    {
      d.setDate(d.getDate() + 7);
    }
}
else if (d.getDay() < nextD)
{
  d.setDate(d.getDate() + (d.getDay() - nextD));
}
else
{
  d.setDate(d.getDate() + nextD + (7 - d.getDay()));
}
d.setHours(0,nextT,0,0);

alert(d);

Optimisations are always welcome in the comments section.

22 August 2013 16:12 GMT+01:00    Posted By: Adam Saunders
Comments *NEW*

Too view and add comments, click on the article titles and scroll to the bottom of the page.

Twitter Updates
About This Blog

The e-home of Adam Saunders

These are the declassified opinions of Adam Saunders. I take no responsibility for the effect these opinions may have on you. Do not read with care...