Zend - The PHP Company




Calculators

Add Code


Get Age By Date  

Type: code fragment
Added by: mvilla213
Entered: 04/10/2000
Last modified: 01/12/2000
Rating: *** (6 votes)
Views: 10098
Returns age of person by the person's birth date.


<?php

/**************************************************
 *
 * int getAgeByDate(int $mm, int $dd, int $yyyy)
 *
 **************************************************
 *
 * Returns age of person by the person's birth date
 *
 **************************************************
 *
 * Parameters:
 *     $mm   - Month of birth
 *     $dd   - Day of birth
 *     $yyyy - Year of birth
 *
 **************************************************
 *
 * Return value
 *    Age of person
 * 
 **************************************************
 *
 * Author:      Matthew R. Villa <matt@1-percent.com>
 * Last modified: 10.01.2000
 *
 * Copyright (c) 2000 1-Percent.com
 *
 */

function getAgeByDate($iMonth$iDay$iYear) {
    
$iTimeStamp = (mktime() - 86400) - mktime(000$iMonth$iDay$iYear);
    
$iDays $iTimeStamp 86400;
    
$iYears floor($iDays 365.25);
    return 
$iYears;

}

?>


Usage Example


print getAgeByDate(04, 17, 1980);

The result will display "20"

Or, if you want to make sure someone isn't a minor, here is an example of how to validate a birth date:

if (getAgeByDate("04", "17", "1983") > 18) {
    print "Person is a minor!";
}


Rate This Script





Search



This Category All Categories