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

How do I make today's date equal to a specific date?

  const today = new Date();
  today.setHours(0,0,0,0); // Tue May 31 2022
 
  let dateHoliday = new Date('Tue May 31 2022');
  (today == dateHoliday) ? alert('holiday') : alert('regular day');

The code above returns regular day. I want it to be true.

>Solution :

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

You can call .getTime() on both values and then do a compare on the numeric values.

const today = new Date();
today.setHours(0,0,0,0); // Tue May 31 2022
 
let dateHoliday = new Date('Tue May 31 2022');
(today.getTime() === dateHoliday.getTime()) ? alert('holiday') : alert('regular day');
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