Wednesday, April 16, 2008

Cuanto meses de vida tienes?


Alguien en los foros de Scripting Languages del SCN preguntó como podía hacer en PHP para determinar la edad en meses de una persona...Esto es bastante sencillo de hacer, pero como es obvio...Todos hemos sido principiantes alguna vez -:)

Ahí les va el código por si a alguien le sirve...


<?php
if(isset($_POST['Birthday']))
{
$Birthday = $_POST['Birthday'];
list( $day, $month, $year ) = split('[.]',$Birthday);
$year = (date("Y") - $year) * 12;
$month += $year;
echo "You are $month months old";
}
else
{
echo "Please enter your birthday in dd.mm.yyyy format!";
}
?>

<html>
<head></head>
<body>
<form action="<?php print $PHP_SELF?>" method="post">
Birthday: <input type="text" name="Birthday"><br>
<input type="submit" value="Submit">
</form>
</form>
</body>
</html>


Saludos,

Blag.

No comments: