Add weekdays to date

JavaScript, Date · Jan 7, 2021

Calculates the date after adding the given number of business days.

const addWeekDays = (startDate, count) =>
  Array.from({ length: count }).reduce(date => {
    date = new Date(date.setDate(date.getDate() + 1));
    if (date.getDay() % 6 === 0)
      date = new Date(date.setDate(date.getDate() + (date.getDay() / 6 + 1)));
    return date;
  }, startDate);
addWeekDays(new Date('Oct 09, 2020'), 5); // 'Oct 16, 2020'
addWeekDays(new Date('Oct 12, 2020'), 5); // 'Oct 19, 2020'

More like this

  • Add days to date

    Calculates the date of n days from the given date, returning its string representation.

    JavaScript, Date · Nov 28, 2020

  • Add minutes to date

    Calculates the date of n minutes from the given date, returning its string representation.

    JavaScript, Date · Nov 28, 2020

  • Format duration

    Returns the human-readable format of the given number of milliseconds.

    JavaScript, Date · Oct 22, 2020