I have a weird issue with the datepicker in javascript. It has always been working but it breaks on a specific date (25 march 2016) and I don't see what's wrong with it. I do know the code is not optimal.
03/25/2016 to 03/26/2016 is 1 (night) 03/25/2016 to 03/27/2016 is 2 (nights) 03/25/2016 to 03/28/2016 is 2 (nights) << should be 3 03/25/2016 to 03/29/2016 is 3 (nights) << should be 4
The function of the datepicker is to calculate the number of night between to 2 dates. Therefore 1 is substracted from the total.
http://jsfiddle.net/anc7x02g/3/
$(document).ready(function () {
var selector = function (dateStr) {
var d1 = $('#datepickerln1').datepicker('getDate');
var d2 = $('#datepickerln2').datepicker('getDate');
var diff = 1;
if (d1 && d2) {
diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
diff = diff -1;
}
$('#total').val(diff);
}
$("#datepickerln1").datepicker();
$('#datepickerln2').datepicker();
$('#datepickerln1,#datepickerln2').change(selector)
});
What am i doning wrong?