Adding variable days to a date
Copy link to clipboard
Copied
Hi
I have a form field that has a variable number of days (in one or two digits, eg 28, 35 or 78) I wish to add a these number of days to the current todays date, and calcualte the future date.
Example 12 add this number to todays date 12/11/2022 (dd/mm/yyyy) = 23/11/2022 (dd/mm/yyyy)
Is there forms script that can do this?
Copy link to clipboard
Copied
You want to show the result in another field?
Let's say that field name is "Date" as validation script of field where you enter number of days use this:
if(event.value == "")
this.getField("Date").value = "";
else{
var days = new Date();
days.setDate(days.getDate() +Number(event.value));
this.getField("Date").value = util.printd("dd/mm/yyyy", days);}
Copy link to clipboard
Copied
Hi Nesa
Thanks for your reply. Do I have to create a new form field? Where do I place your script in the forms field properties dialogue box, under what tab?
What I am doing is a medication calculator. (see jpeg) And entering the number of loose tablets, unopened boxes, dosage and finaly arriving at a form field that gives the "number of days supply", I thought it would great if the "number of days supply" triggered a last day of meditation with a date in a form field. Many thanks.
Copy link to clipboard
Copied
Use script under 'Validate' tab of "Number of Days Supply" field, and make field where you want to show date is same name as in script. When asking for help on the forum, it would be really helpful to tell us actual field names or show screenshot of fields while in 'Prepare from' tool.
Copy link to clipboard
Copied
Hi Nesa
It works perfectly. Thanks for all your help. I flatten the form using Foxit print facility and the file is very small, ideal for archiving.

