<?php

    /**
     * This function calculates the age acccording to the birthday provided. The function makes use of the
     * strtotime() of PHP to convert the parameter to a timestamp. Therefore this function accepts all the
     * types of input the strtotime() function accepts. For more information about the use of the function
     * please visit http://us.php.net/manual/en/function.strtotime.php
     * 
     * @author Gerard Klomp <glj.klomp@gmail.com>
     * @version 1.0
     * @license MIT License - http://www.opensource.org/licenses/mit-license.php
     * @return integer|boolean Returns age as an integer on success, FALSE otherwise.
     * @param string $dateString String representing the date to be calculated against the current date/time
     */
    function calculateAgeByBirthday($dateString) {
	    
        $timestamp = strtotime($dateString);
        
        if ($timestamp === false || $timestamp == -1) {
            return false;
        }

        return date('Y') - date('Y', $timestamp) - (date('m') < date('m', $timestamp) ? 1 : (date('m') == date('m', $timestamp) && date('d') < date('d', $timestamp) ? 1 : 0));
        
    }

Bovenstaande code werkt met datums die uit een MySQL database worden gehaald.
<?php
    echo calculateAgeByBirthday('1985-07-13 12:00:00');
    echo calculateAgeByBirthday('13 july 1985');
    echo calculateAgeByBirthday('13');
Dit zal 2 maal 23 opleveren (op het moment van schrijven) en eenmaal zal er niets getoond worden omdat de datum niet volledig was.

