5
With reference to these two questions:
I need to compare the dates and I need three distinctions between two dates, she being equal or greater or minor See the example below:
function gerarData(str) {
var partes = str.split("/");
return new Date(partes[2], partes[1] - 1, partes[0]);
}
function teste(){
var data_1 = '03/03/2016';
var data_2 = '03/03/2016';
console.log( gerarData(data_1) );
console.log( gerarData(data_2) );
if ( gerarData(data_1) === gerarData(data_2) ) {
alert("Datas iguais com ===");
}
else if ( gerarData(data_1) == gerarData(data_2) ) {
alert("Datas iguais com ==");
}
else if ( gerarData(data_1) > gerarData(data_2) ){
alert("data_1 > data_2");
}
else if ( gerarData(data_1) < gerarData(data_2) ) {
alert("data_1 < data_2");
}
else{
alert("inconclusivo \n data_1="+gerarData(data_1)+" \n data_2="+gerarData(data_2));
}
}
teste();
Why even the console.log
showing me that they are equal he does not enter the condition that makes this check?
I think you could just add one
+
here:return new Date
, gettingreturn +new Date
.– Sergio
@Sergio why? Give an answer.
– Maniero
@mustache made :)
– Sergio