09-21-2007, 03:11 PM
|
#1 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
|
Calculating an Age from Date of Birth
If you're particularly nosey then calculating an individual's age from their date of birth can be fascinating. Although there is a way to calculate the age using MySQL alone, MySQL shouldn't really be used as a calculator.
The following function will take a time stamp and output you the user's age.
PHP Code:
function getAge($iTimestamp)
{
$iAge = date('Y') - date('Y', $iTimestamp);
if(date('n') < date('n', $iTimestamp))
{
return --$iAge;
}
elseif(date('n') == date('n', $iTimestamp))
{
if(date('j') < date('j', $iTimestamp))
{
return $iAge - 1;
}
else
{
return $iAge;
}
}
else
{
return $iAge;
}
}
Just remember to feed in a time stamp.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|