note 39359 deleted from function.date by derick
| From: | derick@php.net | Date: | Sat, 22 May 2004 13:53:53 +0000 |
| Subject: | note 39359 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69956@lists.php.net to get a copy of this message | ||
Note Submitter: eric_zander@yahoo.com
----
I was looking for a simple way to calculate someone's age. I learned this is no easy task b/c
of the Unix timestamp and many different ways of handling dates prior to 1Jan1970.
Here is my simple way to figure out someone's age without using timestamps:
function Convert_DOB_to_Age($DOB) // $DOB is in YYYY-MM-DD format
{
//explode $DOB to an array for easy processing.
$DOBArray = explode("-", $DOB);
// Get today's year, month and day
$TodayDay = date('d');
$TodayMonth = date('m');
$TodayYear = date('Y');
// The logic
if (($TodayMonth > $DOBArray[1]) || (($TodayMonth == $DOBArray) && ($TodayDay >=
$DOBArray[2])))
{$Age = $TodayYear - $DOBArray[0];}
else {$Age = $TodayYear - $DOBArray[0] - 1;}
// return the age
return $Age;
}