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

Calculating Age based DOB and Today's date

Community Beginner ,
Mar 03, 2022 Mar 03, 2022

Currently, these are the fields I have. 

DoB Field name: Date of Birth

Date Field name: Date of Today [Calculated using the following script] which is read-only so every time our front desk opens this document, the date is automatically filled. 

var fld = this.getField("Date of Today"); fld.value = util.printd("mm/dd/yyyy",new Date());

Age field name: Age

randomdoctor_0-1646322774500.png

 

I am using Acrobat DC. I have my Age to "read-only" as well. Currently, I have this script running and nothing is populating on the Age fields.

event.value = "";
var dobValue = getField("Date of Birth").value;
if (dobValue!="") {
var dob = util.scand("mm/dd/yyyy", dobValue);
var today = new Date();
var age = today.getFullYear() - dob.getFullYear();
if (today.getMonth() < dob.getMonth()) age = age - 1;
if ((today.getMonth() == dob.getMonth()) && (today.getDate() < dob.getDate())) age -= 1;
event.value = age;
}

Help me out on this? I have absolutely no knowledge of Java at all. I am just following instructions on the web.

TOPICS
Create PDFs , JavaScript , PDF forms
4.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 ,
Mar 03, 2022 Mar 03, 2022

Use the script at calculation of field Age.

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 ,
Mar 03, 2022 Mar 03, 2022

Where does you use the script?

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 Beginner ,
Mar 03, 2022 Mar 03, 2022

I am placing the scripts in the Documents JavaScript

randomdoctor_0-1646323768737.png

randomdoctor_1-1646323800743.png

 

 

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 ,
Mar 03, 2022 Mar 03, 2022

Use the script at calculation of field Age.

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 Beginner ,
Mar 03, 2022 Mar 03, 2022
LATEST

This helped so much! Solved! Thank you!!!

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