I would like to inform the client of his Startuday
holyday. The Startuday
begins on person.birthday - 9 months
.
Having the person.birthday, we need to know if today is his Startuday
?
Is there a more elegant/short way to find the date difference in months than the following:
const today = new Date();
const DeltaMonths = 9;
const person = {
name: 'John',
birthday: new Date(
today.getFullYear(),
today.getMonth() + DeltaMonths,
today.getDate() //-2 // uncomment to see the diff
)};
let futureDate = new Date(
today.getFullYear(),
today.getMonth() + DeltaMonths,
today.getDate());
let diff = person.birthday - futureDate;
if (diff === 0)
console.log("Horray %s! Today is your startuday!!!", person.name);
else
console.log("Sorry %s, today is NOT yet your startuday...", person.name);