Calculators
|
|
|
|
<?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(0, 0, 0, $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
|
|
|
|