Skip to main content
Ashley Akers
Known Participant
June 6, 2021
Answered

Age calculation based upon date of birth and date of death in years, months and days.

  • June 6, 2021
  • 3 replies
  • 19195 views

I'm so sorry if I am asking for the 100th time, but i've searched so many posts and not seeing exactly what I need.  I work for a funeral home and we are now typing our arrangement information instead of hand writing them.  For our obituaries we always have to calculate the final age in years, months and days.  I thought if I could do a script to calculate it for me, it would save some time!  But, I know nothing about scripts in adobe.  Can somebody help me with the code?  My document will have the date of birth field and the date of death field, now I just need to have it calculate in years, months, and days in my age field.  PLEASE HELP!

This topic has been closed for replies.
Correct answer bebarth

Thank you!!  Now, how can I change things in order to put the month first versus typing the day?


You have to change:
...
if (util.scand("mm/dd/yyyy",this.getField("Deathday").valueAsString)>=util.scand("mm/dd/yyyy",this.getField("Birthday").valueAsString)) {
...
var DoB=parseInt(birthday[1]);
var MoB=parseInt(birthday[0]);
...
var DoD=parseInt(deathday[1]);
var MoD=parseInt(deathday[0]);
...
That's all for the script.
You also have to change the format of both date fields. Remove the script before changing them, else you will have the alert message!!!
@+

3 replies

ls_rbls
Community Expert
Community Expert
June 8, 2021

Also explore this discussion for additional insights:

 

 

In particular, see the contribution provided by NesaNurani about leap year and roll over dates.

 

try67
Community Expert
Community Expert
June 6, 2021

This might seem like a simple calculation, but it's not. Is it really necessary to show the exact number of days, months and years? Why not just an age in years?

Ashley Akers
Known Participant
June 6, 2021

Yes, it is necessary.  We go to websites that have these calculators currently, but trying to save an extra step.

bebarth
Community Expert
Community Expert
April 8, 2024

I am a newbie to Java script and adobe pro. I am working a PDF form to calculate time in years, months, and days between an upcoming appointment date (ApptDate)  and three other dates in the past (LVDate, DOIDate, and SxDate) I tried using the PDF provided above. When I download the file works, but if I change the name fileds it stops calculating the years, moths, and days. I am not even sure where I should be adding the script. Any help woudl be appreciated. 


Sorry, I can't help you right now because I don't have my computer.... only my phone!

 I will have a look on your file tomorrow.

@+

Inspiring
June 6, 2021

What date format will you be using for both date fields? For example, "dd/mm/yyyy".

Ashley Akers
Known Participant
June 6, 2021

I am using dd/mm/yyyy.  If it makes it easier, I can split the years, months and days into 3 different sections on the form.