How do I subtract 30 days from a certain date, assuming that in the DT_VENC field it reports the date of a due date and in the DT_AVISO field returns the date 30 days before the one informed, in the format dd/mm/aaaa
?
How do I subtract 30 days from a certain date, assuming that in the DT_VENC field it reports the date of a due date and in the DT_AVISO field returns the date 30 days before the one informed, in the format dd/mm/aaaa
?
I believe this is what you want:
function getDataAviso(dataVencimento, dias){
var data = new Date(dataVencimento);
data.setDate(data.getDate() - dias);
var dia = data.getDate();
if (dia.toString().length == 1)
dia = "0"+dia;
var mes = data.getMonth()+1;
if (mes.toString().length == 1)
mes = "0"+mes;
var ano = data.getFullYear();
return dia+"/"+mes+"/"+ano;
}
The way to add or subtract date is by creating a Date object and using the setDate method to set a new value by adding or subtracting the amount of days you want.
var DT_VENC = new Date();
var DT_AVISO = new Date().setDate(DT_VENC.getDate() - 30).toLocaleString("pt-BR");'