Code found in memberlist.php (viewprofile) is
[code:1:b63b55adfe] $age = ”;
if ($config[’allow_birthdays’] && $data[’user_birthday’])
{
list($bday_day, $bday_month, $bday_year) = array_map(’intval’, explode(’-‘, $data[’user_birthday’]));
if ($bday_year)
{
$now = getdate(time() + $user->timezone + $user->dst – date(’Z’));
$diff = $now[’mon’] – $bday_month;
if ($diff == 0)
{
$diff = ($now[’mday’] – $bday_day < 0) ? 1 : 0;
}
else
{
$diff = ($diff < 0) ? 1 : 0;
}
$age = (int) ($now[’year’] – $bday_year – $diff);
}
}[/code:1:b63b55adfe]
Extracting this to a general custom function to use in your custom code 🙂
[code:1:b63b55adfe]/**
* Calculate_age($birhtday), returns age from phpbb3’s user table, field: $row[’user_birthday’]
* Return [age] OR ‘Unknown’
*/
function calculate_age($birthday)
{
$age = ”;
if ($birthday)
{
list($bday_day, $bday_month, $bday_year) = array_map(’intval’, explode(’-‘, $birthday));
if ($bday_year)
{
$now = getdate(time() + $user->timezone + $user->dst – date(’Z’));
$diff = $now[’mon’] – $bday_month;
if ($diff == 0)
{
$diff = ($now[’mday’] – $bday_day < 0) ? 1 : 0;
}
else
{
$diff = ($diff < 0) ? 1 : 0;
}
$age = (int) ($now[’year’] – $bday_year – $diff);
return $age;
}
}
return ‘Unknown’;
}[/code:1:b63b55adfe]
[b:b63b55adfe]Linked at: [/b:b63b55adfe]
http://www.phpbb.com/community/viewtopic.php?f=46&t=1620675&start=0
Leave a Reply