Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


script to calculate age

New Here ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

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

Views

76

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Adobe Community Professional , Jul 22, 2021 Jul 22, 2021

Likes

Translate

Translate
Adobe Employee ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

not sure how to make it work for my needs though

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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;}

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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...

Likes

Translate

Translate

Report

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