Skip to content

JavaScript – get the date from next specific day in week

This is useful if you need to set the start date on a day in the week following a specific date.

/**
 * params
 * date [JS Date()]
 * day_in_week [int] 1 (Mon) - 7 (Sun)
 */
function nextWeekdayDate(date, day_in_week) {
  var ret = new Date(date||new Date());
  ret.setDate(ret.getDate() + (day_in_week - 1 - ret.getDay() + 7) % 7 + 1);
  return ret;
}
 
var date = new Date();
console.log(nextWeekdayDate(date, 5)); // Outputs the date next Friday after today.

About 

10 years + experience in web development working with lots of different technology.

Published inJavaScript

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *