Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
Count days from the beginning of current month to date excluding weekends

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)?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You may build up an array of Dates and check for desired day (not to be Saturday or Sunday):

const workdaysCount = () => 
  [...new Array(new Date().getDate())]
    .reduce((acc, _, monthDay) => {
      const date = new Date()
      date.setDate(1+monthDay)    
      ![0, 6].includes(date.getDay()) && acc++
      return acc      
    }, 0)
    
console.log(workdaysCount())    

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda