7
Every time I pass the difference in dates in the same month, it works, but when it’s between different months, a negative value comes. How do I make a difference between dates? See 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();
I took this code and it worked. var total = (((Date.parse(data2)) - (Date.parse(data1))) / (24 * 60 * 60 * 1000));
– pnet
To 'finalize' the question, post your answer and/or provide feedback on why the answers from colleagues have not worked for you.
– Anderson Madeira
You haven’t got the answer yet?
– durtto
Why haven’t you chosen an answer yet?
– durtto