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

107
Vistas
JavaScript weekday list get

I need to create a JavaScript function for the below requirements. I need to get every week day date list. If you know nodeJs package tell me that. Thank you for your attention.

Example - 
 2022-01-03
 2022-01-04
 2022-01-05
 2022-01-06
 2022-01-07

 2022-01-10
 2022-01-11
 2022-01-12
 2022-01-13
 2022-01-14 
 ..........
 ..........
 until year-end

like this pattern (only Monday to Friday)

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

JavaScript's Date object overflows, so you can use:

for (i=1;i<366;i++) {
if (i%7==1 || i%7==2) continue;
const d = new Date(2022, 0, i);
document.write(d.toDateString(),'<br>');
}

You will need to watch for leap years, and recalculate which days are the weekend every year.

about 4 years ago · Juan Pablo Isaza Denunciar

0

function getWeekDaysForYear(year) {
  const isLeap = year % 4 === 0;
  const numberOfDays = isLeap ? 366 : 365;
  let currentDate = new Date(Date.UTC(year, 0, 0, 0, 0, 0, 0));

  const weekDays = [];

  for(let i = 1; i <= numberOfDays; i++) {
    currentDate = new Date(currentDate.getTime() + 24 * 3600 * 1000);
    if (currentDate.getDay() === 0 || currentDate.getDay() === 6) {
      continue;
    }
    weekDays.push(currentDate.toISOString().split('T')[0]);
  }

  return weekDays;
}
console.log(getWeekDaysForYear(2022));

This is a simple function which returns all the weekdays for the specified year in an array.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Something like this

const endDate = new Date(2022,1,2);
const date = new Date(); //today

while (endDate > date) {
  const weekDay = date.getDay();
  if (weekDay != 6 && weekDay != 0) {
    let year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(date);
    let month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(date);
    let day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
    console.log(`${year}-${month}-${day}`);
  }
  date.setDate(date.getDate() + 1);
}
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