|
This section is just beginning as I've only begun to
scratch the surface of PHP.
Age Script - download
(2K) - Not too long ago I went searching for an easy way to
calculate a person's age with PHP. It ends up that this is no easy task unless
you look at it from a different angle than most people. Here is my simple
solution which does not require any sort of Unix time-stamp. This is important
because different servers handle dates before 1 Jan 1970 differently (mine
seems to handle it as a -1 which is not very useful).
Since I only have one PHP script to post and this is
such a simple script, here is the script for those who do not want to download
it:
//******************************************************************************
//* PHP Age
Calculation Script *
//* *
//* Written by: Eric
Zander *
//* 15
January 2004 *
//* *
//* OK to copy and use
however you want as long as you keep *
//* this notice. *
//******************************************************************************
function Convert_DOB_to_Age($DOB)
{
//explode dates to arrays for easy processing. Format is yyyy-mm-dd
$DOBArray = explode("-", $DOB);
$TodayDay = date('d');
$TodayMonth = date('m');
$TodayYear = date('Y');
if (($TodayMonth > $DOBArray[1]) ||
(($TodayMonth
== $DOBArray[1]) && ($TodayDay >= $DOBArray[2])))
{$Age = $TodayYear - $DOBArray[0];}
else {$Age = $TodayYear - $DOBArray[0] - 1;}
// return the age
return $Age;
}
. |