-5
Dev’s good afternoon!
I am trying to create a script that calculates the final date from an initial date and its term in months. Ex:
Initial date: 01/08/2018 Deadline: 60 months End date: 31/07/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();
}
}
Thanks in advance.
Good afternoon Pedro, nice that you are trying, put there what you have done so far.
– LeAndrade
Dear Pedro, understand something, we’re not a free IT service site, you’re asking for something very specific that would have to be developed, and it’s not what we do here, here what we do is help fix scripts, point out API solutions and explain about technologies, terminology. The way your question is this is like you expect someone to really do everything for you, so I recommend you rephrase the question, present what you tried and read https://answall.com/help ... We have rules and recommendations, if you follow them you will get better results.
– Guilherme Nascimento
@Leandrade, I edited the post to show how far I went. But I’m still trying...
– Pedro Henrique Pereira
@Guilhermenascimento Thanks! If the question is not pertinent I will be deleting... But I just wanted to inform you that I’m a beginner and I’m seeking help as a way of study.
– Pedro Henrique Pereira
I managed with the help of a friend to create the function that generates the final date. What I’m racking my brain right now is where I need to change it so that the date one day goes down, so that the correct deadline.
– Pedro Henrique Pereira