Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda