Notings of Attention™
Acmlmboard 2 Released
Github/GIT | @acmlmboard
Chatting Places
Discord

Affiliates
Super Mario Bros. X | Kuribo64 | NeoRHDN
Views: 12,829,024
Main | FAQ | IRC chat | Memberlist | Active users | Latest posts | Stats | Ranks | Online users | Search
05-18-25 06:00 PM
Guest: Register | Login

0 users currently in AcmlmBoard Developer Zone | 1 bot

Main - AcmlmBoard Developer Zone - profile.php user age calculation
Next newer thread | Next older thread


Arisotura
Posted on 03-05-15 12:05 AM Link | ID: 82740
Developer
pancakes
Level: 84


Posts: 702/1872
EXP: 5659272
Next: 2680

Since: 01-05-12
From: France

Last post: 42 days
Last view: 42 days
Turns out that the method used by AB2.5 yields wrong results (one year off) if the user is old enough.

'Old enough' is typically 100 years or more so it doesn't really matter, though.


I came up with a different method for calculating the member's age. It works fine for all ages, and as a bonus, it doesn't have the requirement of the code that is implemented currently.

if($user['birth'])
{
$months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

$bd = explode('-',$user['birth']);
$birthday = $months[(int)$bd[0]].' '.(int)$bd[1];

$unit = ($bd[1]>=10 && $bd[1]<=13) ? 4 : $bd[1]%10;
switch ($unit)
{
case 1: $birthday .= 'st'; break;
case 2: $birthday .= 'nd'; break;
case 3: $birthday .= 'rd'; break;
default: $birthday .= 'th'; break;
}

if ($bd[2])
{
$birthday .= ', '.$bd[2];

$datenow = explode('-',date("m-d-Y"));
$daynow = $datenow[0]*31 + $datenow[1];

$daybd = (int)$bd[0]*31 + (int)$bd[1];

$age = $datenow[2] - (int)$bd[2];
if ($daybd > $daynow) $age--;

if ($age < 0)
$age = '(born in '.(-$age).' year'.($age==-1?'':'s').')';
else
$age = '('.$age.' year'.($age==1?'':'s').' old)';
}
else
$age = '';
}
else
{
$birthday='&nbsp;';
$age='';
}


This assumes that the user birthday is stored as 'MM-DD-YYYY' or 'MM-DD' when the year is omitted.

____________________
Kuribo64 - melonDS

want some revolution in your coffee?

Squiddy
Posted on 03-05-15 12:20 AM Link | ID: 82741
Banned
Unspecificed Cooling Off Period. Be Safe
Bisexual Empress of the Stolen Title?
Level: 144


Posts: 5789/6751
EXP: 36473219
Next: 237087

Since: 07-17-13

Last post: 3595 days
Last view: 3502 days
All birthdays in the database that are stored as "-1" will need to be changed to "0" and editprofile.php all also need to be updated to enter 0 instead of -1. This is not a criticism, I'm just stating what needs to be done in conjunction with the new age calculation.

Great job! :)

____________________
Sunshine Realm
Welcome to Aqmlm's, the only board with Al-Aq'mlmistrators!

Arisotura
Posted on 03-05-15 12:23 AM Link | ID: 82742
Developer
pancakes
Level: 84


Posts: 703/1872
EXP: 5659272
Next: 2680

Since: 01-05-12
From: France

Last post: 42 days
Last view: 42 days
In my Acmlmboard branch, 'no birthday entered' is represented by an empty string, rather than 0 or -1.

____________________
Kuribo64 - melonDS

want some revolution in your coffee?

Next newer thread | Next older thread
Main - AcmlmBoard Developer Zone - profile.php user age calculation


Acmlmboard v2.5.6 (06/11/2024)
© 2005-2025 Acmlm, Emuz, et al.

Page rendered in 0.039 seconds. (759KB of memory used)
MySQL - queries: 66, rows: 476/509, time: 0.033 seconds.