11
rated 0 times
[
12]
[
1]
/ answers: 1 / hits: 153181
/ 11 Years ago, mon, november 11, 2013, 12:00:00
I am calculating 12 days before date from today date. But it does not return the correct date.
For example, for today dat, 11/11/2013 in (mm/dd/yyyy), it returns 10/30/2013 when it should return 10/31/2013.
Here is the code
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);
}
More From » date