Whenever I move the date difference in the same month, it works, but when it is between different months, comes a negative value. How do I make a difference between dates? Look at my code. The error is in total
Code
if (($("#txtDateStart").val().split("/") == "") && ($("#txtDateEnd").val().split("/") == "")) {
data1 = new Date();
data2 = new Date();
}
else {
var dtInicio = $("#txtDateStart").val().split("/");
var dtFim = $("#txtDateEnd").val().split("/");
data1 = new Date(dtInicio[2] + "/" + dtInicio[1] + "/" + dtInicio[0]);
data2 = new Date(dtFim[2] + "/" + dtFim[1] + "/" + dtFim[0]);
}
var total = data2.getDate() - data1.getDate();