|
|
|
View previous topic
::
View next topic
|
| Author |
Message |
ramon fincken Site's programmer
 Get a free globally recognized avatar It's free!
Joined: 03 Aug 2007 Posts: 256 Location: A'dam/Diemen, The Netherlands
|
Posted: Sat May 30, 2009 11:43 am Post subject: [solution][snipplet] Phpbb3 code to calculate user age |
|
|
Code found in memberlist.php (viewprofile) is
| Code: | $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);
}
} |
Extracting this to a general custom function to use in your custom code
| Code: | /**
* 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';
} |
Linked at:
http://www.phpbb.com/community/viewtopi...mp;start=0 |
|
| Back to top |
|
 |
Google adsense Advertisement
|
Posted: Sat May 30, 2009 11:43 am Post subject: [solution][snipplet] Phpbb3 code to calculate user age |
|
|
Advertisement
|
|
| Back to top |
|
 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|