Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!