Q:

How to increase the date from current date with specific format?

I want to create a date with the specific format (2015-03-25),  which is the increment of 9 days from the current date for certain requirements. Below is my code, however, when the current date approaches the end of the month such as 23 or 24 it is increasing by 9 and returning 32. which is not acceptable for the date. how to validate and return to next month's appropriate date? I want to do it in plain java-script I want to skip the libraries like moment.js for now. 

const date = new Date("2015-03-25");
let currentDate = new Date();
let returnDate = ((currentDate.getDate())>=10)? (currentDate.getDate()+9) : '0' + (currentDate.getDate());

A:

To set a date on a date object, you need to use the setDate() method. You can also convert your long conditional statement into a shorter if.

let currentDate = new Date("2015-03-25");
let returnDate = new Date(currentDate);

if( currentDate.getDate() >= 10 )
  returnDate.setDate(currentDate.getDate() + 9);

console.log(returnDate);

More here: Date.setDate()

