Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Add years to a date

Participant ,
Nov 26, 2022 Nov 26, 2022

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?

TOPICS
JavaScript
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Nov 26, 2022 Nov 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);}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2022 Nov 26, 2022

Hi,

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

@+

 

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2022 Nov 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);}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 26, 2022 Nov 26, 2022

Than you very much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2022 Nov 26, 2022

Hi,

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

@+

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 26, 2022 Nov 26, 2022
LATEST

Thank you very much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines