Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Age Calculation

Avatar

Level 1

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?

0 Replies

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