var ourDate = new Date();
//Change it so that it is 7 days in the past.
var pastDate = ourDate.getDate() - 7;
//Log the date to our web console.
In the example above we:
- We deducted 7 days from the current date.
- We changed our original date to the “7 days ago” date by using the setDate method.
- We logged it to our web console for example purposes.
Note: If you want to get “30 days ago” instead of a week ago, then you can simply deduct 30 instead of 7. Hopefully, you found this short guide to be useful!