I bet it's something really stupid, but I'm tired and looking for a quick escape, so please pamper me. The goal is to be able to add arbitrary days to a date built from a type string 2015-01-01.
firstDate = '2015-01-01';
var t1_date = new Date(firstDate);
t1_date.setTime( t1_date.getTime() + 90 * 86400000 );
lastDate = getFormattedDate(t1_date);
console.log("Two dates: ", firstDate, lastDate);
function getFormattedDate(date) {
var year = date.getFullYear();
var month = date.getMonth().toString();
month = month.length > 1 ? month : '0' + month;
var day = date.getDate().toString();
day = day.length > 1 ? day : '0' + day;
return year + '-' + month + '-' + day;
}
And then:
I get a conclusion that is wrong because I add 90 days.
Two dates: 2015-01-01 2015-02-31
source
share