Expand my Community achievements bar.

Calculate A Fixed Length Future Date Based On User Provided Date

Avatar

Level 3

Does anyone know how I would (using date field) have a user choose a date (call it Field1) and have it calculate 30 days from whatever date is chosen in Field1) and auto populate it in another filed (call it Field2). Ideally user would not have to 'click' in Field2 to have information populated...

So user picks January 1st in Field 1 + 30 days = January 30th in Field 2

6 Replies

Avatar

Level 10

Here is a sample just do the similar thing..

https://acrobat.com/#d=ToUoyINGUhY-qM2KO*Eh5w

In this sample, it adds 45 days to the selected date and populate in the next field.

Thanks

Srini

Message was edited by: Srini Dhulipalla

Message was edited by: Srini Dhulipalla

Avatar

Level 3

Srini,

This seems to work, however when you try to select a start date for the very first time it defaults in a date of for the second (default date) of 02/14/1900. If you choose another start date it seems to work properly?

Update: This seems to be related to having this code in the change action anyone know how to get around this?

Avatar

Level 3

This works but is there any way to have it (Field2) populate without the user having to 'click out of the current section field'? So essentially the Field2 date would automatically populate once a user a chosen the Field1 date thus eliminating the user having to actually click in Field2 or in surrounding whitespace?

Avatar

Level 10

I placed the code in the earlier form in the exit event..If you want to display the calculated date upon changing the date, then the code needs to be moved to Change event.

Here is the sample that has the script moved to Change event.

https://acrobat.com/#d=TraLCmZ-W5yvgAvZaMNP9Q

While you reuse the approach, you need to pay attention to the date patterns that are used in this sample. If you change the pattern, then the code needs to be modified accordingly.

Thanks

Srini

Avatar

Level 3

Well for the life of me I can't figure this out. Given the code:

DateTimeField2.rawValue = Num2Date(Date2Num(xfa.event.newText, "M/D/YYYY")+30,"MM/DD/YYYY");

It should add 30 days to the chosen date. But some reason it's off by a day. If I choose 6-1-2010 it picks 7-1-2010, if I pick 7-1-2010 it picks 7-31-2010. I'm really stumped where it's picking up the extra day?