I'm currently building a website for event schedules and such, so basically it displays all the upcoming events and the date of it, and what I want it to do is to sort of highlight the event a day before the actual event happens.
let a = new Date(); // today date, will be updated everyday
let b = targetDate; // you need to set this to whichever date you want to check.
a.setDate(a.getDate()+1); // make current date increase by 1;
if(a == b){ // check if target date is equal to today's date + 1
alert('Today is the day you were waiting for.'); // trigger required event here
}
You can check multiple dates here using for loop.
Look into Luxon. It makes handling these types of problems much eaiser.
But to be more helpful, what you want to do is determine if the date you're comparing is greater than the beginning of tomorrow, and less than the end of tomrrow. There's lots of ways to do this, but the most straight-forward way for a new dev would be something like this in "vanilla" JavaScript:
function isTomorrow(date) {
var now = new Date();
var tomorrow = new Date(now.setDate(now.getDate() + 1));
var startOfTomorrow = tomorrow.setUTCHours(0,0,0,0);
var endOfTomorrow = tomorrow.setUTCHours(23,59,59,999);
return Number(date) > startOfTomorrow && Number(date) < endOfTomorrow;
}
let date = new Date()
date.setDate(date.getDate() - 1)
date;