Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

389
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda