0

i'm trying to write a function to get the the date after 5 days from a start day including just workingdays(Mon-Frid). the problem i did not find a way to add just five working day from my array after my start day the calculation should avoid Saturday and Sunday.

var weekday = [
  "Sunday",
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
];
const date = new Date();
let day = date.getDay();

// let day = weekday[date.getDay()];
function getDayAfter5Days(startDate) {
  const date = new Date();
  let day = weekday[date.getDay()];
  var currentDate = startDate;
  if (day != "Saturday" && day != "Sunday") {
    after5Wday = date.getDay() + 5
  }
  console.log(after5Wday);
}
getDayAfter5Days(new Date())
nasro
  • 3
  • 6
  • I made you a snippet. I had to rename the passed var but you are not using it `currentDate = startDate` does nothing – mplungjan Feb 03 '22 at 08:22
  • var currentDate = startDate should probably be var currentDate = startday – Raffael Feb 03 '22 at 08:23
  • 1
    What is the actual expected output? A weekday like "Monday"? Or a date like 2022-02-03? – derpirscher Feb 03 '22 at 08:23
  • And actually, for all days except Saturday and Sunday you can just as 7 days, because for instance adding five workdays to a Monday will always result in a Monday again. For Saturday you add 6, and for Sunday you add 5 – derpirscher Feb 03 '22 at 08:27
  • @derpirscher the expected output is a date like 2022-02-03 – nasro Feb 03 '22 at 08:29
  • @derpirscher the most importat thing that i have to add five days to my start day what ever is the startday. for ex ; startday : 03-02-2022(Thursday) =>after adding 5 workingday the output is (10-02-2022) or starday is 05-02-2022(Saturday) => + 5 days (saturday and sunday would not be count) output 14-02-2022 – nasro Feb 03 '22 at 08:32
  • Welcome to Stack Overflow! Visit the [help], take the [tour] to see what and [ask]. Please first ***>>>[Search for related topics on SO](https://www.google.com/search?q=javascript+add+day+not+sunday+site:stackoverflow.com)<<<*** and if you get stuck, post a [mcve] of your attempt, noting input and expected output using the [`[<>]`](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Feb 03 '22 at 08:36

0 Answers0