0
I need to check if the interval between two dates does not exceed 12 months, for this I did the following in javascript:
var dataFinal = new Date();
var dataInicial = new Date();
dataFinal.setMonth($data.formInput.dataSelecionada.getMonth() +12);
dataInicial.setMonth($data.formInput.dataSelecionada.getMonth() -12);
var situacao = true;
if ($data.formInput.dataSelecionada02 >= dataFinal || $data.formInput.dataSelecionada02 <= dataInicial){
situacao = false;
} else {
situacao = true;
}
return (dataInicial+' | '+dataFinal);
But if I select the date 01/01/2017
initially works normally, me is displayed 01/01/2016
and 01/01/2018
but if I change the date to 01/02/2016
instead of the dates becoming 01/02/2015
and 01/02/2017
is returned to me 01/02/2016
and 01/02/2018
, that is, the day and month even change but the year does not, how could solve this?