I have a MVC View which the user can enter 2 dates. The Controller makes the correct calculations, however I want the amount of days to be shown immediatly. So I added some Javascript to the page.
<div class="col-md-10">
<input type="date" name="DateOut" min=@DateTime.Now.ToString("yyyy-MM-dd") id="date_out" onchange="showDates()">
</div>
</div>
<text>Until:</text>
<div class="form-group">
<div class="col-md-10">
<input type="date" name="DateIn" min=@DateTime.Now.ToString("yyyy-MM-dd") id="date_in" onchange="showDates()">
</div>
</div>
<script>
function showDates() {
document.getElementById("show_amount_of_days").innerHTML = document.getElementById("date_in").value - document.getElementById("date_out").value;
}
</script>
The problem is that the element seems to be a string and not a date type, so Javascript is unable to calculate the days.
How do I fix this?