Dev's good afternoon!
I'm trying to create a script that calculates the end date from an initial date and its deadline in months. Ex:
Starting date: 08/01/2018 Deadline: 60 months End Date: 7/31/2023 (60 months - 1 day)
function calcDate() {
var dat = document.getElementById("data").value;
var meses = document.getElementById("meses").value;
if(dat != "" && meses != "") {
var sp = dat.split("/");
dat = new Date(sp[2], sp[1]-1, sp[0]);
var m = meses%12;
var y = Math.floor(meses/12);
var tmp = dat.setMonth(dat.getMonth()+m);
var tmp = dat.setYear(dat.getFullYear()+y);
var f = new Date(tmp);
document.getElementById("final").value = ("0" + f.getDate()).slice(-2) + "/" + ("0" + (f.getMonth() + 1)).slice(-2) + "/" + f.getFullYear();
}
}
Thank you in advance.