Question:
How do I create code in HTML that will generate an age from a date of birth?
2010-08-31 23:18:09 UTC
Im creating profiles for some of our models on our website and rather than have to constantly update the ages is there a way I can create some code where I just put the date of birth and then the code automatically generates the models age from that on the profile ?
Four answers:
?
2010-09-01 07:06:32 UTC
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
Stefan C
2010-09-01 01:22:14 UTC
What you really need to to store the model details in a database, such as MySQL, and to access it using a server-side scripting language, such as PHP. PHP allows you to get the details from the database, manipulate them, and then send them to the browser as HTML.



Unfortunately, you would need to learn PHP, a whole new programming language, and you would also need to know the SQL Query language to get data from the database. This is worth the effort though. You already know HTML so you are halfway there.



I'd expect learning PHP to take you 6 months, but if you have experience of the C programming language, which is similar, then this would be reduced.



It's also worth checking that your website host supports PHP and MySQL before you start. Most of them do, as they have become widely used, but not all do. Many hosts provide them as part of their normal package, others charge extra to add them.



Hope that helps...
ciolli
2016-10-23 02:12:40 UTC
There a pair of techniques they are able to tell. An examination of the teeth and different developmental milestones like the fusion of the cranium, some thing with reference to the pelvis and different outwardly observable signs and indications (which i'm no longer able to bear in mind precise now) are the ordinary techniques. i'm particular their are others greater invasive techniques too.
2010-08-31 23:43:51 UTC
Because html is a markup language you wont be able to do it purely with html, you will need to use javascript as html only defines the layout and look of a webpage.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...