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

Affiliates
Super Mario Bros. X | Kuribo64
Views: 9,000,386
Main | FAQ | IRC chat | Memberlist | Active users | Latest posts | Stats | Ranks | Online users | Search
04-23-24 05:27 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, in Link | ID: 82740
Developer
pancakes
Level: 83


Posts: 702/1868
EXP: 5411121
Next: 21100

Since: 01-05-12
From: France

Last post: 680 days
Last view: 219 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, in Link | ID: 82741
Banned
Unspecificed Cooling Off Period. Be Safe
Bisexual Empress of the Stolen Title?
Level: 142


Posts: 5789/6751
EXP: 34789251
Next: 179178

Since: 07-17-13

Last post: 3205 days
Last view: 3112 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, in Link | ID: 82742
Developer
pancakes
Level: 83


Posts: 703/1868
EXP: 5411121
Next: 21100

Since: 01-05-12
From: France

Last post: 680 days
Last view: 219 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.5 (10/04/2020)
© 2005-2024 Acmlm, Emuz, et al.

Page rendered in 0.037 seconds. (760KB of memory used)
MySQL - queries: 70, rows: 478/510, time: 0.030 seconds.