Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

392
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda