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

Inserting an auto-populate date that is a year from another auto-populated date

New Here ,
Jun 23, 2021 Jun 23, 2021

I inserted a field that has today's date auto-populate. I want to create another field that will auto-populate a date that is the same month and day but the year will be the NEXT year.

 

Using today as an example:

Here is the auto-populated field for today's date

CourtGinger_0-1624485623543.png

And this is what it's called: 

CourtGinger_1-1624485665027.png

I need a field that will populate the date to Jun 23, 2022 automatically (based off the other date).

Hope that made sense.

 

Is this possible? 

TOPICS
Edit and convert PDFs , General troubleshooting , JavaScript , PDF forms
6.4K
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 24, 2021 Jun 24, 2021

A better solution is to use the built-in methods of the Date object to do it, which will take care of the Feb 29th issue without having to hard-code each leap year into it:

 

var sDate = this.getField("Cur_Date").valueAsString;
if (sDate) {
	var cDate = util.scand("mmm dd, yyyy", sDate);
	cDate.setFullYear(cDate.getFullYear()+1);
	event.value = util.printd("mmm dd, yyyy", cDate);
} else event.value = "";

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
Adobe Employee ,
Jun 23, 2021 Jun 23, 2021

Hi there

 

Hope you are doing well and sorry for the trouble. As described you want to populate the date field that has the same month and day but the year will be the NEXT year.

 

The workflow that you are trying to achieve is possible using the JavaScript. For more information please check the help page https://acrobatusers.com/tutorials/javascript_console/ and see if that works for you.

 

Regards

Amal

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
Engaged ,
Jun 23, 2021 Jun 23, 2021

@Court & Ginger  use the following script with necessary changes to get a required year :

It is not the best of the answers but it will do for your requirement.

 

//Script:

cDate = util.scand("mmm dd, yyyy", this.getField("Cur_Date").value); //change "Curr_Date" to your date field name
cDay = util.printd("dd",cDate);
cMonth = util.printd("mmm",cDate);
cYear = Number(util.printd("yyyy",cDate)) + 1;   

event.value = cMonth + " " + cDay + ", " + cYear;

 

 

 

 

Hope it helps

 

 

 

 

 

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 ,
Jun 23, 2021 Jun 23, 2021

What is with Feb 29, 2024?

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
Engaged ,
Jun 23, 2021 Jun 23, 2021

@Bernd Alheit  Sir,   i know previous script was not the best of the answer

Plz check this one:


cDate = util.scand("mm/dd/yy", this.getField("Cur_Date").value);;
cDay = util.printd("dd",cDate);
cMonth = Number(util.printd("mm",cDate));
cYear = Number(util.printd("yyyy",cDate));

 

if(cYear%4 == "0" && cMonth == "2" && cDay == "29"){
event.value = (cMonth+1)+ "/" + "1" + "/" + (cYear+1);}


else if(cYear%4 !== "0" && cMonth !== "2" && cDay !== "29") {

event.value = cMonth + "/" + cDay + "/" + (cYear+1)};

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 ,
Jun 24, 2021 Jun 24, 2021

Why not Feb 28?

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
Engaged ,
Jun 24, 2021 Jun 24, 2021

I reckon in this particular case since the date is autopopulated with current date so for next 50 years   cYear%4=="0" will hold good.

 

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
Engaged ,
Jun 24, 2021 Jun 24, 2021

it depends on the user requirement if  he wants 28 then it can be changed .

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
Enthusiast ,
Jun 24, 2021 Jun 24, 2021

What would be correct solution in this case, to show march 1st?

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
Engaged ,
Jun 24, 2021 Jun 24, 2021

@Asim123 I have updated the Script plz check updated Script to take care of Feb 29 situation.

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 ,
Jun 24, 2021 Jun 24, 2021

A better solution is to use the built-in methods of the Date object to do it, which will take care of the Feb 29th issue without having to hard-code each leap year into it:

 

var sDate = this.getField("Cur_Date").valueAsString;
if (sDate) {
	var cDate = util.scand("mmm dd, yyyy", sDate);
	cDate.setFullYear(cDate.getFullYear()+1);
	event.value = util.printd("mmm dd, yyyy", cDate);
} else event.value = "";
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
New Here ,
Jun 24, 2021 Jun 24, 2021

I am trying to respond and it won't 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
New Here ,
Jun 24, 2021 Jun 24, 2021

Thank you everyone for taking the time to figure this out.

 

I forgot to mention that I know nothing about Javascript coding so I need a step by step version lol.

 

I'm assuming that I will need to copy and paste the script below somewhere but that's all I know:

CourtGinger_0-1624546391753.png

Plus I don't know how this will work with other other script that I have for auto-populating today's date:

CourtGinger_0-1624546158348.png

 

Thank you for your patience!

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 ,
Jun 24, 2021 Jun 24, 2021

You need to use this code as the custom calculation script of the second field, and you must adjust the name of the field in the first line of the code to match the actual field name in your file where the current date will appear.

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
New Here ,
Jun 24, 2021 Jun 24, 2021

Ok this is what I tried:.

 

I created a new field and named it this:

CourtGinger_1-1624555036843.png

 

Then I clicked on Javascript editor, clicked on document JavaScripts, and created a new script:

CourtGinger_2-1624555109534.png

 

In Microsoft Word, I typed in the script that you gave me (as best I can), and then copied and pasted it into

the Java sript editor (this is my text from word):

 

CourtGinger_6-1624555504358.png

 

 

Clicked OK, and then it said I had a syntax error: 

CourtGinger_5-1624555370996.png

(The part circled in red above is what was highlighted after I hit "Ok" but when I took a screen shot of it, it highlighted the whole script for some reason)

 

Do you know where my error is?

 

 

 

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 ,
Jun 24, 2021 Jun 24, 2021

The field name has to be in quotes. Also, do not use Word as a code editor! Use a plain-text editor, like Notepad. Or if you want a more professional tool, I highly recommend Notepad++.

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
New Here ,
Jun 28, 2021 Jun 28, 2021

Ok thank you. I typed up the code in Notepad instead.

 

It didn't show it had an error this time but it's not working:

 

CourtGinger_2-1624901417188.png

CourtGinger_0-1624901639822.png

 

CourtGinger_3-1624901460988.png

The second date should be June 28, 2022

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 ,
Jun 28, 2021 Jun 28, 2021

You need to place that code under the custom calculation event of the second field, not as a doc-level script, or alternatively adjust it so that it refers to the field, not to event.value, which won't work in this context.

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
New Here ,
Jun 29, 2021 Jun 29, 2021

Oh ok. I have no idea how to do that lol.

 

Would you mind taking me through each step?

 

It sounds like adjusting it "so that it refers to the field, not to event.value" might be the easier option for me since I have an idea of how to do the doc-level script.

 

Thank you so much for all of the time you are taking to help me!

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 ,
Jun 29, 2021 Jun 29, 2021

Change this line:

event.value = util.printd("mmm dd, yyyy", cDate);

To:

this.getField("name of field").value = util.printd("mmm dd, yyyy", cDate);

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
New Here ,
Jun 29, 2021 Jun 29, 2021

Ok I tried that and it didn't work (I may have done it wrong) but it seems like I need to do something with the part I put below in red (like remove it or replace it with something else)

 

var sDate = this.getField("Year From Now_es_:signer2:date").valueAsString;
if (sDate) {
var cDate = util.scand("mmm d, yyyy", sDate);
cDate.setFullYear(cDate.getFullYear()+1);
this.getField("Year From Now_es_:signer2:date").value = util.printd("mmm d, yyyy", cDate);
} else event.value = "";

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 ,
Jun 29, 2021 Jun 29, 2021

You have to change that too in the same way... However, I don't see when this is going to happen, since the first field will always have a value, no?

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 ,
Jun 29, 2021 Jun 29, 2021

You've making it needlessly complicated. This is all the code you need to populate the two fields:

 

var d = new Date();
this.getField("Field1").value = util.printd("mmm dd, yyyy", d);
d.setFullYear(d.getFullYear()+1);
this.getField("Field2").value = util.printd("mmm 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
New Here ,
Jun 29, 2021 Jun 29, 2021

Yay, it worked!

 

Thank you again so much for your patience!

 

Have a great day!

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
New Here ,
Jul 07, 2021 Jul 07, 2021

Ok, someting is not working correctly when I send it to be compelted and signed electroincally through Adobe Sign.

 

This is what it looks like before I send it through Adobe sign:

CourtGinger_1-1625686891559.png

 

This is what it looks like after I sent it and the student completed it and signed it through Adobe Sign:

CourtGinger_0-1625686821295.png

 

The second date changes back to 2021 when it should be 2022.

 

Any ideas?

 

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