It can't be done in pure HTML
You will need to use a scripting language of some type.
It could be done before you upload pages to your website using a pre-processor such as PPWizard.
It could be done with a client-side script written in Javascript.
It could be done in a server-side script written in a language such as PHP.
If you use a server-side script the date could be stored in a database, but this would not be necessary. You could just store the birth date in the page on which you are going to show the age as in the following example:
"http://www.w3.org/TR/html4/loose.dtd" >
Age from DoB
Age from DoB
function getYearsSince ($YYYYMMDD_In)
{
// Parse Input Date Into Local Variables
// Assumes Input In Form: YYYYMMDD
$yIn=substr($YYYYMMDD_In, 0, 4);
$mIn=substr($YYYYMMDD_In, 4, 2);
$dIn=substr($YYYYMMDD_In, 6, 2);
// Calculate Differences Between Inpute Date And Now
// By Subtracting input date From Current Date
$ddiff = date("d") - $dIn;
$mdiff = date("m") - $mIn;
$ydiff = date("Y") - $yIn;
// Check If Input Month Has Been Reached
if ($mdiff < 0)
{
// Input Month Not Reached
// Subtract 1 Year From Years
$ydiff--;
} elseif ($mdiff==0)
{
// Input Month Currently
// Check If BirthdayDay Passed
if ($ddiff < 0)
{
// Input Day Not Reached
// Subtract 1 Year From Years
$ydiff--;
}
}
return $ydiff;
}
?>
// Example Age Input
$DateOfBirth=19770226;
// Calculate Age Using Function:
$Age= getYearsSince ($DateOfBirth);
// Display Results
echo "A person born on ".$DateOfBirth." is now ".$Age." years old.";
?>
If you are interested in the PPWizard as a solution see: http://www.html-tags-guide.com/html-software.html