arkkhoax
04-06-2008, 11:30 AM
This is most likely very simple and easy to do but I can't figure out how to output the users age in vbulletin based on their registration birth date. There does not seem to be a variable built in for it. Any help would be appreciated.
Thanks.
--------------- Added 1207524531 at 1207524531 ---------------
I think all the code needs to do is subtract the birth date year from the current year to get the age. Could anyone help me?
--------------- Added 1207529081 at 1207529081 ---------------
Oh, after much hunting and pulling my hair out I figured out how to get the age of the user. Hope other people searching around find this of help.
The variable that holds the birthdate is $vbulletin->userinfo['birthday']
To then turn it into an age I used this function (http://snippets.dzone.com/posts/show/1310).
function birthday ($birthday)
{
list($month,$day,$year) = explode("-",$birthday);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($month_diff < 0) $year_diff--;
elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;
return $year_diff;
}
echo birthday($vbulletin->userinfo['birthday']); //prints age
Thanks.
--------------- Added 1207524531 at 1207524531 ---------------
I think all the code needs to do is subtract the birth date year from the current year to get the age. Could anyone help me?
--------------- Added 1207529081 at 1207529081 ---------------
Oh, after much hunting and pulling my hair out I figured out how to get the age of the user. Hope other people searching around find this of help.
The variable that holds the birthdate is $vbulletin->userinfo['birthday']
To then turn it into an age I used this function (http://snippets.dzone.com/posts/show/1310).
function birthday ($birthday)
{
list($month,$day,$year) = explode("-",$birthday);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($month_diff < 0) $year_diff--;
elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;
return $year_diff;
}
echo birthday($vbulletin->userinfo['birthday']); //prints age