Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

if(‘2022-04-30’ < ‘2022-05-30’)
{

// true
}

>Solution :

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');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading