I need to check if the interval between two dates does not exceed 12 months, so 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, I get 01/01/2016
and 01/01/2018
but if I change the date to 01/02/2016
instead of the dates they become 01/02/2015
and 01/02/2017
I am returning 01/02/2016
and 01/02/2018
, that is, the day and the month until they change however the year no, how could I solve this?