I am working on a date comparison for our application. The goal is take the Start Date the user inputs, and check it against the Operator/Region Effective Date which acts as the date a new list of product prices can be used. We want to see if there is an Effective Date 7 days in the future on the Start Date. If so, we want to display a message and let them know the prices are changing soon.
I figure the best thing to do is add 7 days to the Start Date and then see if its less then or equal to the Effective Date, if so, that would mean it is within the range. I just dont know how to add 7 days to the Start Date. Everything I have tried is giving me an "Invalid Date" back. Any ideas?
Code I've Tried So Far
public checkStartDates = () => {
const checkDates = this.state.checkDate;
const region = this.state.well.region;
const d1 = new Date(checkDates.startDate + 7);
const d2 = new Date(region.effectiveDate);
console.log(d1, d2);
if (d1 > d2) {
alert ("Error!");
}
}
public checkStartDates = () => {
const checkDates = this.state.checkDate;
const region = this.state.well.region;
const d1 = new Date(checkDates.startDate + 7);
d1.setDate(d1.getDate() + 7);
const d2 = new Date(region.effectiveDate);
console.log(d1, d2);
if (d1 > d2) {
alert ("Error!");
}
}