I am calculating a range of days between two dates with hours, minutes and seconds as follows:
function calcularDiasAusencia(fechaIni, fechaFin)
{
var fecha1 = new Date(fechaIni.substring(0,4),fechaIni.substring(5,7),fechaIni.substring(8,10));
var fecha2 = new Date(fechaFin.substring(0,4),fechaFin.substring(5,7),fechaFin.substring(8,10));
var diasDif = fecha2.getTime() - fecha1.getTime();
var dias = Math.round(diasDif/(1000 * 60 * 60 * 24));
document.getElementById('diasAusentismo').value = dias+1;
}
Where In date is 2016-10-31 20:14:31 and End date is 2016-11-03 20:14:35, counting from October 31 until November 3 there should be 4 days but the system shows only 3 in the same way I get the bad calculation doing it in the following way
What can generate the error so that the function is throwing incorrect values?