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

229
Views
How can I update expected value with old value?

I have one object

objTime = {
    "scheduleStartDate": "2022-07-13T12:00:00.540+00:00",
    "slotDuration":30,
    "noOfSlots":5,
}

I have to add scheduleEndDate dynamically by using slotDuraion key and noOfSlots is my loop length.

for (let i = 0; i < objTime.noOfSlots; i++) {
          let startDateTime = moment(objTime.scheduleStartDate);
          let expectedEndDateTime = moment(startDateTime).add(objTime.slotDuration, "minutes");
          console.log(
            `Start : ${moment(startDateTime).format("DD-MM-YYYY hh:mm:ss")} | End : ${moment(expectedEndDateTime).format("DD-MM-YYYY hh:mm:ss")}`
          );
        }

But it not works as accept I want o/p like this.

Start : 13-07-2022 05:30:00 | End : 13-07-2022 06:00:00
Start : 13-07-2022 06:00:00 | End : 13-07-2022 06:30:00
Start : 13-07-2022 06:30:00 | End : 13-07-2022 07:00:00
Start : 13-07-2022 07:00:00 | End : 13-07-2022 07:30:00
Start : 13-07-2022 07:30:00 | End : 13-07-2022 08:00:00

Any moment.js function for same I am using NodeJS. Thanks in advance.

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

0

just a little tweak to your implementation to manipulate the date time using the i value

const objTime = {
    "scheduleStartDate": "2022-07-13T12:00:00.540+00:00",
    "slotDuration": 30,
    "noOfSlots": 5,
}
for (let i = 0; i < objTime.noOfSlots; i++) {
    let startDateTime = moment(objTime.scheduleStartDate).add(objTime.slotDuration * (i), "minutes");
    let expectedEndDateTime = moment(objTime.scheduleStartDate).add(objTime.slotDuration * (i + 1), "minutes");
    console.log(`Start : ${moment(startDateTime).format("DD-MM-YYYY hh:mm:ss")} | End : ${moment(expectedEndDateTime).format("DD-MM-YYYY hh:mm:ss")}`);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></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!