I am trying to get a date from an html input to javascript, substract 3 years from it and then place the new date back into another html date input field.
I got the substraction to work with the current date but I can not get it to work when I fetch a date from an html input.
Below my code that works:
<input id="InputDate" data-role="datepicker"/>
<input id="OutputDate" data-role="datepicker"/>
<script type="text/javascript">
var dt = new Date(); // this line I want to replace with the next 2 lines!
//var inDate= document.getElementById("InputDate").value;
//var dt = new Date(inDate);
dt.setFullYear(dt.getFullYear() - 3);
var datestring = ("0" + dt.getDate()).slice(-2) + "." + ("0"+(dt.getMonth()+1)).slice(-2) + "." + dt.getFullYear();
document.getElementById("OutputDate").value = datestring;
When I fetch a date from the input field I get 'aN.aN.NaN' back into the output field. I have tried document.getElementById("InputDate").valueAsDate instead, but this did not work either. When I place an alert(dt) after the instantiation of dt I get 'Invalid Date'.
Any suggenstions how to get the fetched date in the DateObject correctly?
Regards, Manu