0

I have tried to get the current date, which works with the following code:

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
today = yyyy+'-'+mm+'-'+dd;
console.log(today);

Result:

2016-12-14

But now I want to add 14 days, which works and will display

2016-12-28

But when I want to add 21 days, the days will go up to 35 so the result will be:

2016-12-35

Which of course is not a correct date. So how do I get the date in yyyy/mm/dd format + 14 days but the yyyy/mm being correct?

Preamas
  • 1
  • 7

1 Answers1

0
var days=2;

date.setTime( date.getTime() + days * 86400000 );

Hope this will help you.

Mehmood
  • 933
  • 5
  • 17