Php calculate your age script

<?php

if ( isset( $_POST["month"] ) )
{
$bmonth = intval( $_POST["month"] );
$bday = intval( $_POST["day"] );
$byear = intval( $_POST["year"] );

$date1 = time ();
$date2 = mktime ( 0, 0, 0, $bmonth, $bday, $byear );

$dateDiff = $date1 – $date2;
$fullDays = floor($dateDiff/(60*60*24));
$fullHours = floor(($dateDiff-($fullDays*60*60*24))/(60*60));
$fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);
$years = floor( $fullDays / 365 );
$months = ceil( $fullDays % 365 / 30 );

if ( $date2 == false )
{
$message = “ERORRE: Invalid birth date given; must be greater than 12/14/1901.”;
}
else if ( $years == 0 )
{
$message = “Your approximate age is $months month(s).”;
}
else
{
$message = “Your approximate age is ‘$years’ year(s) and ‘$months’ month(s).”;
}

echo ‘<span style=”color:#990000; font-weight:bold; font-size:14px; font-family:Verdana, Arial, Helvetica, sans-serif;”>’.”$message<br/>”.’</span>’;
}

?>

<form action=“<?php echo $_SERVER["PHP_SELF"]; ?>“ method=“POST”>
<p><strong>Month:</strong>
<input type=“text” name=“month” size=“8″ maxlength=“2″ />
<strong>Day:</strong>
<input type=“text” name=“day” size=“8″ maxlength=“2″/>
<strong>Year:</strong>
<input type=“text” name=“year” size=“8″ maxlength=“4″/></p><br /><br />

<p style=”padding-left:80px;”>

<input type=“submit” value=“Calculate age!”/>

</p>
</form>

Follow

Get every new post delivered to your Inbox.