09-21-2007, 10:58 PM
|
#4 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 713
Thanks: 2
|
I'm not sure of the logic on Village Idiot's function (1. Get difference between now and birth date in seconds; 2. Push that into date function, which accepts timestamps, not random seconds; 3. Expect to retrieve a year).
Wildhoney's code, whilst I don't see any problems with the functionality, is a wee bit of a mess (mostly because I never really liked elseifs). The code can be squished into the following function which behaves identically to Wildhoney's but, I think, is a little neater.
PHP Code:
function getAgeSalathe($iTimestamp)
{
// See http://php.net/date for what the first arguments mean.
$iDiffYear = date('Y') - date('Y', $iTimestamp);
$iDiffMonth = date('n') - date('n', $iTimestamp);
$iDiffDay = date('j') - date('j', $iTimestamp);
// If birthday has not happen yet for this year, subtract 1.
if ($iDiffMonth < 0 || ($iDiffMonth == 0 && $iDiffDay < 0))
{
$iDiffYear--;
}
return $iDiffYear;
}
__________________
|
|
|
|