I wrote the following JavaScript. But, it does not work. Can please someone suggest what I need to do to get the number of years by subtracting two input dates.
<script type="text/javascript">
$(function () {
$("#startdate, #enddate").keyup(function () {
$("#totalyears").val(+$("#enddate").val() - +$("#startdate").val());
});
});
</script>
My HTML code:
<div>
<label>Start</label>
<input type="date" name="startdate" id="startdate" autocomplete="off" class="form-control">
</div>
<div>
<label>End</label>
<input type="date" name="enddate" id="enddate" autocomplete="off" class="form-control">
</div>
<div>
<label>Total Years</label>
<input type="date" name="totalyears" id="totalyears" autocomplete="off" class="form-control">
</div>