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.
CodePudding user response:
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');