If you use the setDate
function, it will add the number of days that you want, and you will not have to worry about changing month or year, it will done automatically. To compare dates, you can simply use the >
and <
operators as you would do with any number (actually under the hood, a Date in Javascript is a number).
Example:
var now = new Date();
var nextWeek = new Date(now);
nextWeek.setDate(nextWeek.getDate() + 7);
var tomorrow = new Date(now);
tomorrow.setDate(tomorrow.getDate() + 1);
if (tomorrow > now && tomorrow < nextWeek)
alert('All good!');