I am trying to get number of Days
between 2 Dates, I have searched this on net and found pretty good solution..but when i apply this, its giving me NaN
. I am unable to understand whats wrong in this code, Kindly check it and guide me what i am doing wrong here,
HTML CODE
<input id="date_from" class="form-control input-sm" type="text" name="date_from" required>
<input id="date_to" class="form-control input-sm" type="text" name="date_to" required>
JS CODE
function parseDate(str) {
var mdy = str.split('/')
return new Date(mdy[2], mdy[0]-1, mdy[1]);
}
function daydiff(first, second) {
return Math.round((second-first)/(1000*60*60*24));
}
$(document).ready(function(){
$("#date_to").change(function(){
alert(daydiff(parseDate($("#date_from").val())- parseDate($("#date_to").val())));
alert($("#date_from").val());
});
});
Output
Nan