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

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

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 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