Designate a variable called "date" to store the current date:var date = new Date('25 Dec 2010');
Output the result to the console to ensure the above step is correct:console.log(date);
In the "month" date type, within the "date" object, subtract 12 from the current number. This will give you a date 12 months in the past, stored as the current date: date.setMonth(date.getMonth() -- 12);
Again, output the result. The new date should be exactly 12 months prior to the current date (in the example used above, the new date would be "25 Dec 2009"):console.log(date);
Tips & Warnings
- Make sure you follow proper syntax, such as ending lines with a semicolon.