Skip to main content
MartinKoss
Participating Frequently
June 19, 2020
Answered

Calculate 1 Year Expiry Date (2 date fields)

  • June 19, 2020
  • 2 replies
  • 5220 views

Hello. My apologies if this is a lame and newbie question but, well, I am an Acrobat Newbie. We only bought it to make one PDF.

 

I have been hunting around to find out how to have 2 date fields but when a date on the first one is selected, the second date field is automatically populated with the date 1 year from the first one. So, basically, the same date in the following year minus 1 day.

 

As I said, I am a newbie and don't expect to ever be more than a newbie with Acrobat so any help would be amazing.

 

Thank you.

 

Martin

This topic has been closed for replies.
Correct answer Old_Salt

I had a similar solution but applying a calculation script to Date1. In my case I used "mmm d, yyyy" format. Good solution, Karl_Heinz_Kremer

 

 

if (event.target.value != "") { // check if populated else script will fail.
	var d = new Date(event.target.value); // gets selected date from "Date1" field
	var DateNextYear = new Date(d.getFullYear()+1, d.getMonth(), d.getDate()-1);
	var fld = this.getField("Date2");
	fld.value = util.printd("mmm d, yyyy",DateNextYear); //assign future date to "Date2" field
	//Adjust the field formatting in "fld.value" to match the formatting set for the field. In this case I used "mmm d, yyyy".
}

 

2 replies

Participating Frequently
July 8, 2024

How can I do tis in Adobe Sign with their expression maker? I simply want to have a field that calculates the signed date field + 2 years. I followed the example in the article "Add calculated fields to a form"https://helpx.adobe.com/sign/using/calculated-fields.html#SupFun and it doesn't work. I've played with and it it seems like the expression I want to make should work but no dice, what am I missing? The was to add 2 years addDate "y" to the field [Date 1).

Participating Frequently
July 8, 2024

 dateAdd(d, signedDate, 3)– This expression uses the “dateAdd" function and specifies adding 3 days to the date on which this agreement gets signed. So if the document gets signed on 5/22/2016, the resulting value of the expression will be 5/25/2016 (this is from the "Add calculated fields to a form") so you'd think adding 730 days would update the date to 2 years...it didnt would doing this either

Karl Heinz  Kremer
Community Expert
June 19, 2020

You would use a JavaScript calculation field for the 2nd filed. The following should work:

 

 

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

 

 

 This assumes that you are using a mm/dd/yyyy date format - if that is not the case, you need to adjust the script. 

Old_Salt
Old_SaltCorrect answer
Participating Frequently
June 19, 2020

I had a similar solution but applying a calculation script to Date1. In my case I used "mmm d, yyyy" format. Good solution, Karl_Heinz_Kremer

 

 

if (event.target.value != "") { // check if populated else script will fail.
	var d = new Date(event.target.value); // gets selected date from "Date1" field
	var DateNextYear = new Date(d.getFullYear()+1, d.getMonth(), d.getDate()-1);
	var fld = this.getField("Date2");
	fld.value = util.printd("mmm d, yyyy",DateNextYear); //assign future date to "Date2" field
	//Adjust the field formatting in "fld.value" to match the formatting set for the field. In this case I used "mmm d, yyyy".
}

 

MartinKoss
Participating Frequently
June 21, 2020

This worked a treat too! Thank you.