Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!