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

160
Vistas
Add weekly dates between years

I have a requirement to get all the weekly dates between two years like

Today date is - 13th Sep 2021
After 3 years - 13th Sep 2024

So I need a collection of all the weekly dates between these two dates.

this.allSelectedRegions.push(date as any);

So how to achieve it.

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

0

We can use a while loop to keep adding dates until we reach the required end date. To add 7 days to a date we'll use Date.getDate() and Date.setDate(). This should also handle DST transitions.

const startDate = new Date(2021, 8, 13);
const endDate = new Date(2024, 8, 13);

let date = startDate;
let result = [];
while (date <= endDate) {
    result.push(date);
    date = new Date(date);
    date.setDate(date.getDate() + 7);
}

console.log('Results:', result.map(d => d.toDateString()))

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this

var endDate = new Date(2024,8,13);
var startDate = new Date(2021,8,13);
var currentDate = startDate;
while(currentDate < endDate)
{
    document.getElementById("dateList").innerText += currentDate + "\n"; 
    currentDate.setDate(currentDate.getDate() + 7);
}
<div id="dateList"></div>

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