By Jan on Monday, 02 November 2015
Likes 0
Views 0.9K
Votes 0
What is the getFieldValue for 'age'?

I know the getFieldValue for birthday is 'BIRTHDAY', and that works...
But I only want to display the age, no date.

--Jan
Hey Jan,

Unfortunately if you use this function getFieldValue, it actually only display user birthday date instead of show their age directly, you can try to use my following suggestion code re-compute the age again.


$id = JRequest::getInt( 'id' , null );

// current user profile id
$my = Foundry::user($id);

// Get your current birthday custom field unique key e.g. BIRTHDAY
$birthdayDate = $my->getFieldValue('BIRTHDAY');

// Pass birthday date into this section
$birthDate = new DateTime($birthdayDate);
$now = new DateTime();

// Use this formula generate to age
$age = floor(($now->format('U') - $birthDate->format('U')) / (60*60*24*365));
echo $age; // Result


By the way, I am really sorry but unfortunately our support policy does not cover customizations Hope you understand.
·
Monday, 02 November 2015 12:49
·
0 Likes
·
0 Votes
·
0 Comments
·
Wow... didn't expect it would be like this...
And... it works!! like a charm!

Appreciate it Arlex, thanks a lot!

--Jan
Jan
·
Monday, 02 November 2015 19:14
·
0 Likes
·
0 Votes
·
0 Comments
·
You're welcome, glad to heard your issue resolved.
·
Monday, 02 November 2015 19:16
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post