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

166
Views
Iterate between two dates till first date is before the second

I have two dates in unix:

let start: number = 1632988953;
const end: number  = 1638259353;

I need to iterate over this two dates, witch will calculate the new start date in each iteration.

So, I have a while structure like below:

const datesArray = [];
while (start <= end) {
    let newDate = dayjs.unix(start).add(5, 'day').unix();

    datesArray.push(newDate);
    
    start = newDate;
}

When I start this while in the function, it iterates infinitely killing my browser, can someone tell me what is wrong here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It is working fine, execute the snippet to see for yourself

let start = 1632988953;
const end  = 1638259353;

let condition = true;
console.log("before : ",condition);
const datesArray = [];
while (start <= end) {
    let newDate = dayjs.unix(start).add(5, 'day').unix();
    datesArray.push(newDate);
    start = newDate;
    condition = start <= end;
}
console.log("after : ",condition);
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script>dayjs().format()</script>

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!