wildmanmatt
New member
Hi,
I am trying to have a field display the current age of a person's record based on their date of birth. I have created my field for Age and setup a calculated field function like this
function dadabik_age ($params){
//explode the date to get month, day and year
$birthDate = explode("/", $params(date_of_birth));
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md")
? ((date("Y") - $birthDate[2]) - 1)
: (date("Y") - $birthDate[2]));
echo "Age is:" . $age;
}
I would want this to be correct when viewing the record. When I apply the function, the age field just remains blank.
Can anyone see what I'm doing wrong? Or think of a better way to do it?
Thanks,
Matt
I'm not sure if I'm using the wrong function? Or if I should be using a JS function instead?
I am trying to have a field display the current age of a person's record based on their date of birth. I have created my field for Age and setup a calculated field function like this
function dadabik_age ($params){
//explode the date to get month, day and year
$birthDate = explode("/", $params(date_of_birth));
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md")
? ((date("Y") - $birthDate[2]) - 1)
: (date("Y") - $birthDate[2]));
echo "Age is:" . $age;
}
I would want this to be correct when viewing the record. When I apply the function, the age field just remains blank.
Can anyone see what I'm doing wrong? Or think of a better way to do it?
Thanks,
Matt
I'm not sure if I'm using the wrong function? Or if I should be using a JS function instead?