To learn this, you need to know the following and you are done
Just create a date variable. Set the value of the date to any previous date you want by subtracting the number of days you wanna go back.
Sat Oct 13 2018 11:14:09 GMT+0530 (India Standard Time)
This will print the date we had 5 days ago.
Now let just take any date we want then subtract.
var date1 = new Date('2018-05-26'); date1.setDate(date1.getDate()-5); document.write(date1);
Mon May 21 2018 05:30:00 GMT+0530 (India Standard Time)
Don’t worry about the time zone. It will take the zone from your system.
n is the value of days which you wanna deduct or subtract from your given date. ( or system date, in case you did not put anything in the Date() )
You may also be interested in,