Skip to main content
Inspiring
November 26, 2022
Answered

Add years to a date

  • November 26, 2022
  • 2 replies
  • 2669 views

Hi
I would like to find a script that allows me to find this event:
in the field this.getField("DATA").value I insert a date, for example 11/28/2022
in the field this.getField("YEARS").value I insert the number of years, for example 25
I would like to find in the "EXPIRATION" field where I insert the function the last day of the month following the date resulting from the sum.
In this example the result should be 12/31/2047
More examples
Date 12/28/2022 + 25 years = the last day of the month following the expiry = 01/31/2048
Date 12/10/2022 + 25 years = the last day of the month following the expiry = 01/31/2048

Please, can someone help me?

This topic has been closed for replies.
Correct answer bebarth

Hi,

Here is my proposal (for not having worked for nothing...) 😉

@+

 

 

2 replies

bebarth
Community Expert
bebarthCommunity ExpertCorrect answer
Community Expert
November 26, 2022

Hi,

Here is my proposal (for not having worked for nothing...) 😉

@+

 

 

ENE5CD9Author
Inspiring
November 26, 2022

Thank you very much!

Nesa Nurani
Community Expert
Community Expert
November 26, 2022

Use this as custom calculation script of "EXPIRATION" field:

var date = this.getField("DATA").valueAsString;
var cNum = Number(this.getField("YEARS").valueAsString);

if(!cNum || date == "")
event.value = "";
else{
var d = util.scand("mm/dd/yyyy", date);
d.setFullYear(d.getFullYear() +cNum);
d.setMonth(d.getMonth() + 2);
d.setDate(0);
event.value = util.printd("mm/dd/yyyy",d);}
ENE5CD9Author
Inspiring
November 26, 2022

Than you very much