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

219
Visualizações
check min date and max date using javascript

Having to dates like this '2022-04-30' & '2022-05-30'

using javascript how can evaluate which dates is lower ? I tried to convert them to milliseconds but with this format date I dont know how

example

if('2022-04-30' < '2022-05-30') {

// true }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

EDIT: As pointed out by @RobG the dates are in the ISO format so there is no need for dates at all:

if ('2022-04-30' < '2022-05-30')
  console.log('true')

However this does not work with other date formats, for example:

if ('30-04-2022' < '30-05-2020')
  console.log('returns true, but is incorrect')
  
if (new Date('30-04-2022') < new Date('30-05-2020'))
  console.log('returns false')

ORIGINAL ANSWER: You are trying to compare strings not dates. Try this:

const date1 = new Date('2022-04-30');
const date2 = new Date('2022-05-30');

if (date1 < date2) {
  console.log('true');
}

Or shorter:

if (new Date('2022-04-30') < new Date('2022-05-30'))
  console.log('true');

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