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

Affiliates
Super Mario Bros. X | Kuribo64 | NeoRHDN
Views: 13,743,805
Main | FAQ | IRC chat | Memberlist | Active users | Latest posts | Stats | Ranks | Online users | Search
07-05-25 01:46 PM
Guest: Register | Login

0 users currently in AcmlmBoard Developer Zone | 1 guest | 3 bots

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: 85


Posts: 702/1873
EXP: 5691480
Next: 207060

Since: 01-05-12
From: France

Last post: 41 days
Last view: 34 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: 144


Posts: 5789/6751
EXP: 36674380
Next: 35926

Since: 07-17-13

Last post: 3643 days
Last view: 3550 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: 85


Posts: 703/1873
EXP: 5691480
Next: 207060

Since: 01-05-12
From: France

Last post: 41 days
Last view: 34 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.663 seconds. (760KB of memory used)
MySQL - queries: 70, rows: 482/515, time: 0.657 seconds.