note 51117 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 15 Jan 2006 12:47:03 +0000 |
| Subject: | note 51117 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101843@lists.php.net to get a copy of this message | ||
Note Submitter: squid at anime-sanctuary dot net
----
A little function who calculate people age with their date of birth.
The format of date used is the one used in mysql table. (For example: 2004-10-23)
<?php
function CalcAge($date_of_birth) { // YYYY-MM-DD
$cur_year=date("Y");
$cur_month=date("m");
$cur_day=date("d");
$dob_year=substr($date_of_birth, 0, 4);
$dob_month=substr($date_of_birth, 5, 2);
$dob_day=substr($date_of_birth, 8, 2);
if($cur_month>$dob_month || ($dob_month==$cur_month && $cur_day>=$dob_day) )
return $cur_year-$dob_year;
else
return $cur_year-$dob_year-1;
}
?>