Copy link to clipboard
Copied
HI! I am trying to calculate mother's age in years on baby's birth date. I have a field to enter the mother's birthdate (BM DOB) and a field to enter the baby's birth date (Acq Date). Is this possible to auto-calculate in a read-only text box?
Copy link to clipboard
Copied
See this great sample file: https://abracadabrapdf.net/file/Age_Capitaine.pdf
Copy link to clipboard
Copied
Try this as custom calculation script of 'age' field:
var date1 = this.getField("BM DOB").valueAsString;
var date2 = this.getField("Acq Date").valueAsString;
if (date1 === "" || date2 === "")
event.value = "";
else {
var mdob = new Date(date1);
var bdob = new Date(date2);
var age = bdob.getFullYear() - mdob.getFullYear();
if (bdob.getMonth() < mdob.getMonth() ||
(bdob.getMonth() === mdob.getMonth() && bdob.getDate() < mdob.getDate()))
age--;
event.value = age;}
Copy link to clipboard
Copied
This returns NaN in the age field.
Copy link to clipboard
Copied
Don't use any Format in the Age field, and set it to read only.
Copy link to clipboard
Copied
See this great sample file: https://abracadabrapdf.net/file/Age_Capitaine.pdf
Copy link to clipboard
Copied
Yes, it's possible to auto-calculate the mother's age on the baby's birth date using a script or formula in the read-only text box. Consider using an Age calculator because this feature saves time, ensures accuracy, and simplifies record-keeping.