Skip to main content

I have the following javascript and it only adds day and does not change month. Anything wrong with the code?

For example, this example I am using the current date.

The due date is showing 5/8/2017 instead of 6/8/2017 

May 25 2017 - Updated the following code by adding +1 with getMonth(). The code is now working.

var date = new Date();
date.setDate(date.getDate() + 15);
var control = NWF$("#"+ jsDueDate);
if(control.val() == "")
{
control.val(date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear());
}

it's because getMonth() returns zero based value.

ie. January == 0

so you have to use date.getMonth()+1


Reply