I am working on program that displays the number of workdays in the month passed up until today. For example, today is the 9th of September, so the program should display the number 7, as there has been one weekend up until that day. If today was the 20th of September, the program should display the number 14, as there has been 3 weekends up until that date. (With weekends I mean only Saturday and Sunday).
This is the code I currently have:
date = new Date();
let dayD = date.getDate();
let newDay = dayD - 2; // Temporarily done manually as I don't have the code to automatically do it yet
console.log(newDay);
I have seen several similar questions but none that was similar enough or that actually helped me. So, how could I count the days in the month passed until today, but excluding the weekends (Only workdays)?