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

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

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