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

script to calculate age

New Here ,
Jul 22, 2021 Jul 22, 2021

Hi Team,

 

I am after a script to workout a persons age based on their date of birth. the dob field is called DOB and i use dd/mmm/yyyy

 

TIA

TOPICS
JavaScript , PDF forms
2.3K
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 ,
Jul 22, 2021 Jul 22, 2021
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 ,
Jul 22, 2021 Jul 22, 2021

Hi Ben

 

Hope you are doing well and sorry for the trouble.

 

The workflow you are trying to achieve is possible using the JavaScript. For more information please check out the help page https://acrobatusers.com/tutorials/javascript_console/

 

Hope it will help

 

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
Community Expert ,
Jul 22, 2021 Jul 22, 2021
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 22, 2021 Jul 22, 2021

not sure how to make it work for my needs though

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 ,
Jul 23, 2021 Jul 23, 2021
LATEST

Try use this as "Custom calculation script" in field where you want to show age:

event.value = "";
var dv = this.getField("DOB").value;
if (dv!="") {
var dob = util.scand("dd/mmm/yyyy", dv);
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;}

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 ,
Jul 22, 2021 Jul 22, 2021

This issue was discussed on the forums many times, including complete code examples of how to do it. Try searching around a bit of "age calculation" or similar keywords...

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