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

87
Vistas
MomentJS returning unexpected result

Unsure what I am doing wrong with my dates together with moment.js.

I have the following code:

function(value) {                        
  const startDate = moment(this.parent.startDate).format("DD/MM/YYYY")
  const endDate = moment(value).format("DD/MM/YYYY")
  console.log("SE",startDate,endDate)
  return moment(startDate).isSameOrBefore(moment(endDate))
}

The output of my console.log for both startDate and endDate is:

SE 15/08/2021 19/08/2021

For some reason though, when calling this function, it is saying that my:

End date must be greater than or equal to start date

which based on my return moment(startDate).isSameOrBefore(moment(endDate)), should not be the case as end date 19/08/2021 is after start date 15/08/2021

What am I missing?

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

0

Compare the original dates, not the formatted dates, since moment.js doesn't know that they're in DD/MM/YYYY format.

function(value) {                        
  const startDate = moment(this.parent.startDate).format("DD/MM/YYYY")
  const endDate = moment(value).format("DD/MM/YYYY")
  console.log("SE",startDate,endDate)
  return moment(this.parent.startDate).isSameOrBefore(moment(value))
}
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