I have a weird issue with datepicker in javascript. It always worked, but a specific date comes (March 25, 2016), and I do not understand what is wrong with him. I know that the code is not optimal.
03/25/2016 to 03/26/2012 - 1 (night) 03/25/2012 to 03/27/2012 - 2 (nights) 03/25/2012 to 03/28/2016 - 2 (nights) <must be 3 03/25/2012 to 03 / 29/2016 - 3 nights (should be 4
The datepicker function is to calculate the number of nights between two dates. Therefore, 1 is subtracted 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);
diff = diff -1;
}
$('#total').val(diff);
}
$("#datepickerln1").datepicker();
$('#datepickerln2').datepicker();
$('#datepickerln1,#datepickerln2').change(selector)
});
What am I doing wrong?
source
share