@kirkslater,
Since you asked it in another thread, here is what you need
Put this function in your functions.php or bp-custom.php
/**
* Get Age from BuddyPress date of Birth
* <a href='http://buddypress.org/community/members/param/' rel='nofollow'>@param</a> string $dob_field_name :name of the DOB field in xprofile, like Dob or Date of Birth
* <a href='http://buddypress.org/community/members/param/' rel='nofollow'>@param</a> int $user_id : the user for which you want to retrieve the age
* <a href='http://buddypress.org/community/members/param/' rel='nofollow'>@param</a> string $format: the way you want to print the difference, look t <http://php.net/manual/en/dateinterval.format.php> for the acceptable agrs
* @return string :the formatted age in year/month
*/
function bpdev_get_age_from_dob($dob_field_name,$user_id=false,$format="%y Years, %m Month(s), %d days"){
if(!$user_id)
$user_id=bp_displayed_user_id ();
$dob_time=xprofile_get_field_data($dob_field_name, $user_id);//get the datetime as myswl datetime
$dob=new DateTime($dob_time);//create a DateTime Object from that
$current_date_time=new DateTime();//current date time object
//calculate difference
$diff= $current_date_time->diff($dob);//returns DateInterval object
//format and return
return $diff->format($format);
}
and Now you can output the age anywhere using
echo "Age".bpdev_get_age_from_dob("DOB Field Name");//display for the displayed user
//or
echo "Your Age".bpdev_get_age_from_dob("DOB Field Name",bp_loggedin_user_id());//display for logged in user
You can pass the Dob field name, user_id and the format in which you want to show the difference.
here is the gist in case the code gets garbled: https://gist.github.com/1257476
Hope that helps.
PS: It will need php 5.3.3 or above.