I need to make a function increment X days to a date. The problem is that the date is coming as string
in this format: dd/mm/yyyy
and at the time of assigning the X days to that date, says that it does not recognize the var that will be incremented by X days, such as var_tal is not a function
. How do I proceed? here is the example in the fiddle.
That way it does not work:
var dt_exclusao = '26/11/2015';
var periodo = 60;
var nova_data = new Date(dt_exclusao);
//alert(dt_exclusao.setDate(dt_exclusao.getDate() + periodo));
alert(nova_data);
alert(periodo);
nova_data.setDate(nova_data.getDate() + periodo);
alert(nova_data);
But that's how it works, that means the past format is the problem:
var dt_exclusao = '2015-11-26T00:00:00';
var periodo = 60;
var nova_data = new Date(dt_exclusao);
//alert(dt_exclusao.setDate(dt_exclusao.getDate() + periodo));
alert(nova_data);
alert(periodo);
nova_data.setDate(nova_data.getDate() + periodo);
alert(nova_data);
In the fiddle it worked, but on the page did not. The function on the page looks like this:
function montaDataSubstituicaoPrestador(dt_exclusao, periodo){
var arrData = dt_exclusao.split('/');
var novaData = new Date(arrData[2] + '-' + arrData[1] + '-' + arrData[0]);
alert(arrData);
alert(dt_exclusao);
alert(periodo);
alert(novaData);
novaData.setDate(novaData.getDate() + periodo);
alert(novaData);
}
The big difference is that fiddle
I put dt_exclusao
on hand and the function I get. Date mounted on novaData
looks like this: NaN
. The arrData
is correct, type: 26,11,2015, but the assembly gives error NaN
.