I have two textboxes that are used to select a date - "Valid from date" and "Valid To Date". When a date gets entered into the Valid from date textbox I want to automatically add 30 days and put this date into the valid to date textbox. So I added an onchange to the textbox:
<asp:TextBox runat="server" ID="txtValidFromDate" onchange="UpdateValidToDate(this.value)" Width="80px" rel="datepicker"></asp:TextBox>
function UpdateValidToDate(date){
var ValidToDate = new Date(date);
var numberOfDaysToAdd = 30;
ValidToDate.setDate(ValidToDate.getDate() + numberOfDaysToAdd);
document.getElementById('<%= txtValidToDate.ClientID %>').value = ValidToDate;
}
The problem is the date format is 07/12/2016 so when I call ValidToDate.getDate()
the format is wrong. The day and month are getting mixed up. So if I add this code I can see that the day gets set to 12 and the month gets set to 7 when it should be the other way around.
var day = ValidToDate.getDate();
var month = ValidToDate.getMonth()+1;
How do I format the date coming in from the textbox so when I add 30 days it returns the correct date?