Skip to main content
Inspiring
May 6, 2024
Answered

how to calculate a date based of another date and a dropdown box ?

  • May 6, 2024
  • 1 reply
  • 578 views

Hi, I have this code that allow me to give a date based on another date :

 

    var cDate = this.getField("DateDebut18").value;
    if (cDate) {
    var d1 = new Date();
    d1 = util.scand("dd/mm/yyyy", cDate);
    d1.setFullYear(d1.getFullYear() + 1); // this adds one year
    d1.setDate(d1.getDate() - 1); // this subtracts one day
    event.value = util.printd("dd/mm/yyyy", d1);
    }

 

However, I need a code that allow me to obtain a date based on another date and the value of a dropdown box that have three options : 1 year, 2 years, 3 years. What is the code ? Thank you.

This topic has been closed for replies.
Correct answer try67

Just change this line:

d1.setFullYear(d1.getFullYear() + 1);

To:

d1.setFullYear(d1.getFullYear() + Number(this.getField("Years").valueAsString));

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 7, 2024

Just change this line:

d1.setFullYear(d1.getFullYear() + 1);

To:

d1.setFullYear(d1.getFullYear() + Number(this.getField("Years").valueAsString));

Inspiring
May 7, 2024

It works, thanks a lot !