Expand my Community achievements bar.

Age Calculation

Avatar

Former Community Member

I've got the following script inside a text field.calcualte

I have two fields:

1st Today's Date (calculated field, read only) "Today"

2nd DOB date picker "DOB"

3rd Age Text Field "Age"

this is the script I have in "Age"

// define some time constants

var fSec = 1000; //second

var fMin = 60 * fSec; // minute

var fHr = 60 * fMin; // hour

var fDay = 24 * fHr; // day

var fYear = 365.25 * fDay; // year

var strStart =  this.getField("DOB").value; // dob

//var strToday = util.printd("mmm dd, yyyy", new Date()); // get system date time

var strToday = this.getField("Today").value;

// compute if there are values for dob and today

if(strStart.length & strToday.length) {

var dob = util.scand("mmm d, yyyy", strStart); // convert dob to date time object

var today = util.scand("mmm d, yyyy", strToday); // convert today to date time object

var diff = today.valueOf() - dob.valueOf();  // compute difference of values

diff = diff + fDay; // adjust to count today as a counted day

event.value = Math.floor(diff/ fYear); // truncate to whole years

}

The code looks good but doesn't produce any results....any help/assistance?

1 Reply

Avatar

Level 10

Hi,

One aspect: this.getField("Today").value is javascript that is used in AcroForms (forms developed in Acrobat).

When working in LC Designer the javascript is slightly different. The equivalent would be:

varStr Today = Today.rawValue; 

Haven't looked at the rest, but give that a try.

Niall