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

83
Vistas
MomentJS isAfter returning incorrect data

I want to know if a date (2021-11-09) is after another date (2021-11-11) in YYYY-MM-DD format, which should be false, right ?

  console.log(
    moment("2021-11-09", "YYYY-MM-DD", true).isAfter(
      "2011-11-11",
      "YYYY-MM-DD",
      true
    )
  );

but, above code return true.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

the doc of momentjs states:

If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.

As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day

So you should use a unit instead of format string though it seems the result is same.

console.log(
  moment("2021-11-09", "YYYY-MM-DD", true).isAfter(
    "2011-11-11",
    "day" //"YYYY-MM-DD"
  )
)
console.log(
  moment("2021-11-09", "YYYY-MM-DD", true).isAfter(
    "2021-11-11",
    "day" //"YYYY-MM-DD"
  )
)
<script src="https://unpkg.com/moment@2.29.1/moment.js"></script>

about 4 years ago · Juan Pablo Isaza Denunciar

0

The dates you're comparing in code and the ones in your questions are not aligned. And code is returning true correctly. Because 2021-11-09 is indeed after 2011-11-11

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