View Single Post
Old 09-21-2007, 03:11 PM   #1 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Wink 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.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
maZtah (01-10-2009)