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

391
Views
Using dayjs() to see if a date is after another one

I am trying to loop through an array and push the tasks that are after today in another array. Could someone tell me what I am doing wrong? (task.reminderDate is the correct type, I have used it in other functions and it works)

  taskList.forEach((task) => {
      if (dayjs().isAfter(dayjs(task.reminderDate))) {
        missedFilter.push(task);
      }
    });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think you are misunderstanding how isAfter works.

console.log(dayjs("2031-01-01").isAfter(dayjs())); //This returns true

Currently you are comparing if today is after reminder date. So you want to change the order of your dates:

 if (dayjs(task.reminderDate).isAfter(dayjs()))

Now you are comparing if reminderDate is after today's date

about 4 years ago · Juan Pablo Isaza Report

0

Your description doesn't describe what you are doing, but I am not sure which is wrong:

This is testing to see if "today" is after (task.reminderDate)

So, the output should be that the array "missedFilter" should be filled with tasks with a reminder date prior to today.

That seems like a reasonable thing to do, but you state that you want to push tasks that are after today into an array.

I don't think there's anything wrong with your actual code, but there may be something wrong with the semantics of what you intend to be doing.

e.g. if you genuinely want tasks with a reminderDate in the future, you should reverse the code:

var today = dayjs();
taskList.forEach((task) -> {
  if (dayjs(task.reminderDate).isAfter(today))) {
    missedFilter.push(task);
  }
});

(Note also, pushing the dayjs initializer outside the loop. Minor efficiency, but also helps with clarity.)

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!