I realized that the best way to increment or decrement date in javascript is by adding or reducing miliseconds of the date. Here is the example:
The output will be like this
Lets make a function for it.
If you want to increment the date, pass positive value in dayValue. If you want to decrement the date, pass negative value in it. Let's try to get the date 10 days from today and 10 days before today.
Here is the result
var today = new Date(); var tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000)); var yesterday = new Date(today.getTime() - (24 * 60 * 60 * 1000));
The output will be like this
Today is
Tomorrow is
Yesterday is
Tomorrow is
Yesterday is
Lets make a function for it.
function incrementOrDecrementDate(date, dayValue) { return new Date(date.getTime() + (dayValue * 864e5)); }
If you want to increment the date, pass positive value in dayValue. If you want to decrement the date, pass negative value in it. Let's try to get the date 10 days from today and 10 days before today.
var tenDaysFromNow = incrementorDecrementDate(new Date(), 10);
Here is the result


