9

I have the following date:

2014-10-29

I am trying to add one year to the date (not 365 days, but 1 year):

var newDate = new Date('2014-10-29');

newDate.setDate(newDate.getFullYear() + 1);

var yyyy = newDate.getFullYear().toString();
var mm = (newDate.getMonth() + 1).toString();
var dd = newDate.getDate().toString();

var mmChars = mm.split('');
var ddChars = dd.split('');
var newClosingDate = yyyy + '-' + (mmChars[1] ? mm : "0" + mmChars[0]) + '-' + (ddChars[1] ? dd : "0" + ddChars[0]);

This returns 2020-04-06, which is obviously wrong.

What am I doing wrong here?

0

1 Answer 1

14
var date = new Date("2014-10-29"); 
date.setFullYear(date.getFullYear() + 1);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.