I've been trying to calculate the date that is 12 days before today's date, but I'm running into an issue where it's not returning the correct result. For instance, if today is November 11, 2013 (mm/dd/yyyy), the code returns October 30, 2013 instead of the expected October 31, 2013.
Here is the code snippet I am using:
var d = new Date();
d.setDate(d.getDate() - 12);
d.setMonth(d.getMonth() + 1 - 0);
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
if (curr_month < 10 && curr_date < 10) {
var parsedDate = "0" + curr_month + "/" + "0" + curr_date + "/" + curr_year;
alert(parsedDate);
} else if (curr_month < 10 && curr_date > 9) {
var parsedDate = "0" + curr_month + "/" + curr_date + "/" + curr_year;
alert(parsedDate);
} else if (curr_month > 9 && curr_date < 10) {
var parsedDate = curr_month + "/" + "0" + curr_date + "/" + curr_year;
alert(parsedDate);
} else {
var parsedDate = curr_month + "/" + curr_date + "/" + curr_year;
alert(parsedDate);
}