Copy link to clipboard
Copied
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!
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!!!
@+
Copy link to clipboard
Copied
What date format will you be using for both date fields? For example, "dd/mm/yyyy".
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Yes, it is necessary. We go to websites that have these calculators currently, but trying to save an extra step.
Copy link to clipboard
Copied
OK, what's the correct result for DOB "31/03/1980" and DOD "01/01/2021"?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
YES, that is exactly what I need!! Can you give me that script?
Copy link to clipboard
Copied
The script is in the PDF file.
Copy link to clipboard
Copied
That script is not accurate.
Copy link to clipboard
Copied
How can we have a calculation more accurate with a number of days different in accordance with the month???
@+
Copy link to clipboard
Copied
If you enter DOB 05/06/2001 and DOD 01/07/2021 you will get 20y 1m and 26days and result should be 20y 0m and 26days so it's off by 1month.
Copy link to clipboard
Copied
Thank you! I was able to get that script to work, but it is off by a day, possibly to account for leap years? How can we account for this in the script?
Copy link to clipboard
Copied
Actually, it is a month off. If I calculate it with the DOB of 7/6/1927 and the date of death as 6/6/2021, it shows me 94 years and 30 days. It is actually 93 years and eleven months.
Copy link to clipboard
Copied
No, @AlainMKS, that calculation isn’t correct as far as I can see. I’m using this site: Date Duration Calculator: Days Between Dates (timeanddate.com).
@Ashley Akers, have you tried asking a site like this if you can license or purchase a copy of their calculation script (is it javascript?) and then running that script inside Acrobat? Is it the different number of days in each month that makes it too difficult for Acrobat's calculation methods? Is it a custom validation script you need? Which field property would you use?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
It is still off a month.
Copy link to clipboard
Copied
@bebarthIf I change even the day to reflect one day different, it will change it on the calculation a month versus a day.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you!! Now, how can I change things in order to put the month first versus typing the day?
Copy link to clipboard
Copied
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!!!
@+
Copy link to clipboard
Copied
This worked perfectly! I can't ever thank you enough for your help!
Copy link to clipboard
Copied
@bebarthI have another issue with this. This file that I created to calculate this goes on a couple of computers with adobe reader and not acrobat. On one computer the file works fine, but the other one, which is a macbook, won't calculate the age but puts in "NaN" in the field. How can I fix this? Thanks!
Copy link to clipboard
Copied
"NaN" stands for "Not a Number", which means they entered the date in a wrong format, or added some additional text to it, which they shouldn't have.
Copy link to clipboard
Copied
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.