These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

age from date of birth.

khayes1
Registered: Jul 25 2007
Posts: 4

I am trying to calculate an age that will be automatically entered into a text box when a person enters their date of birth in another. I am using Adobe LiveCycle Designer.

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
In LiveCycle Designer FormCalc, you can get the number of days from an epoch date with the "Date2Num()" function for the current date and the date of birth. The difference of these 2 numbers will provide you with the number of days since the date of birth. To get the number of years, one can divide by 365.25 and then use the "floor()" function to truncate the fractional years.

George Kaiser

JGKMD
Registered: Jan 21 2008
Posts: 3
New to Acrobat...
Can't seem to find the right Formcalc syntax to get the "Date of Birth" user selection from a Date and time Field passed to the Date2Num() function for the age calculation. Seem to get 0 with everything I have tried?
I suspect the format of the "Date of Birth" value is the problem, but I haven't been able to discover how to reconcile that?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
FormCalc and JavaScript both work with field names and field names can not contain spaces or certain special characters. Also all field names, functions, variables are case sensative. So if you do not have it right it will not work.

I would start with a calculated read only text field for the Age result and then enter the the "Date Of Birth" field name into the FormCalc for the "Calculation" script. Select a date in the "Date of Birth" field, exit the field and observe what happens. You should see something other than zero if you have the field name correct.

Next change the calculation in the field for the "Age" to the Date of Birth field name followed by ".formattedValue". Repeat selecting the Date of Birth and observe what happens. You should now have a formatted value for the selected date.

Now with this information one should be able to get the number of days from the epoch date. Assuming your Date of Birth field is named "DOB" and the format for the display of the 'DOB" field is "MMM D, YYYY" you can get the number of days since the date of birth with:

Date2Num(DOB.formattedValue, "MM D, YYYY") - Date()

The number of years:

(Date2Num(DOB.formattedValue, "MM D, YYYY") - Date()) / 365.25

The whole years:

Floor( (Date2Num(DOB.formattedValue, "MM D, YYYY") - Date()) / 365.25
)

George Kaiser

JGKMD
Registered: Jan 21 2008
Posts: 3
gkaiseril wrote:
FormCalc and JavaScript...
Thanks, this got me there with a trial and error!
David Jones
Registered: Feb 4 2009
Posts: 4
Hi and thanks gkaiseril

I also got this to work with a bit of trial and error ( I am new to livecycle and also not a strong programmer in anything)

I get teh correct number of years produced however it shows as a negative number eg -6

Is there a way to avoid that?

Regards

DLOL - just realised - simple maths ! Multiply it by -1

Age = Floor((Date2Num(DOB.formattedValue, "MMM D, YYYY") - Date())/365.25)*-1

D
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Ooops, need to subtract the Dob from today and add 1 day.

Age = Floor( ( (Date() - Date2Num(DOB.formattedValue, "MMM D, YYYY") ) / 365.25 )
You need to be very careful with the format of the DOB field to get this to work properly.

George Kaiser

David Jones
Registered: Feb 4 2009
Posts: 4
Thanks for the correction !

D
hammer09
Acrobat 9
Registered: May 19 2006
Posts: 15
Is there a reason why -109 is displayed in the Age field?

Chad Chelius
Chelius Graphic Services
chad [at] cheliusgraphicservices [dot] com

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
If you do not have a value in the DOB field, 0 is used in the computation so you are computing the years from the Epoch date and not years for the difference between the current date and the DOB . So you may need to test to see if you have a valid date to process before performing the computation.

George Kaiser

lorimevans
Registered: Apr 1 2011
Posts: 2
I am using LiveCycle designer for my form that needs to calculate age from the difference between DOB and "date of request"...not Epoch calendar. Any suggestions? Here is the simple calculation I need using my field names:

RequestDate - DOB = Age (rounded to years)

I set my age field to a read only calculation. I am an Adobe novice...thanks
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
If you do not want to use LiveCycle Designer's FormcCalc Epoch date of January 1, 1900 for assigning sequential number to each date since the Epoch, you can use JavaScirpt's date object that assigns a unique sequence number to each millisecond since January 1, 1970.

There are desk calendars that have the Juliann date of the year on each days page and one can use this to compute the number of days between 2 dates within the same year. So if one picks any date for a starting point and continues beyond the end of a year, the computation is not much different than computing the number of 2 dates within a year, but one can cover a much longer period.

You only need to change the current date's days since the Epoch date to the number of days since the Epoch date for your field 'RequestDate'.


Age = Floor( ( (Date2Num(RequestDate.formattedValue, "MMM D, YYYY") - Date2Num(DOB.formattedValue, "MMM D, YYYY") + 1) / 365.25 )

With comments and expanded

// get number of days for DOB since Epoch date
var nDob = Date2Num(DOB.formattedValue, "MMM D, YYYY")
// get number of days for Request date since Epoch date
var nRequestDate = Date2Num(RequestDate.formattedValue, "MMM D, YYYY")
// compute the difference in days between the Request date and the DOB
var nDiff = nRequestDate - nDOB
// adjustment to include the end date
nDiff = nDiff + 1
// compute to number of years
var nYears = nDiff / 365.25
// truncate the number of years
Floor(nYears)



George Kaiser