Skip to content Skip to sidebar Skip to footer

Js : How To Check If Given Date Is Within 2 Years From Today?

If I have a date time in milliseconds, how do I check if its within 2 years of today in JavaScript ? So far, I have the following: var yearInMs = ( 1000 * 60 * 60 * 24 * 7 * 52 );

Solution 1:

Just at 2 years to today and see if it's greater than the supplied date or time value, e.g.

var d = newDate();
d.setFullYear(d.getFullYear() + 2);

if (d > 1519183763504) {
  console.log('within  2 years')
} else {
  console.log('Not within  2 years')
}

Post a Comment for "Js : How To Check If Given Date Is Within 2 Years From Today?"