hi ..This is a Calculating age using PHP.select your date of birth and get your age.it very simple coding to calculate age. mktime() using to Calculating age ..
Age calculate
echo (date("md", date("U", mktime(0, 0, 0, 29, 12,1990))) > date("md") ? ((date("Y")-1990)-1): (date("Y")-1990));
mktime(0, 0, 0, 29, 12,1990)
29 - date 12 - month 1990-year
Output :
23
Source Code:
if(isset($_POST['submit']))
{
$dd=$_POST['dd'];
$mm=$_POST['mm'];
$yy=$_POST['yy'];
$age = (date("md", date("U", mktime(0, 0, 0, $dd, $mm, $yy))) > date("md") ? ((date("Y")-$yy)-1):(date("Y")-$yy));
echo "Your Age is:".$age;
}
?>
<html>
<head>
<title>Calculating Date</title>
</head>
<body>
<form method="post">
<select name="dd" required>
<option value="">Date</option>
<?php
for($dd=01;$dd<=31;$dd++)
{
echo "<option value='$dd'>$dd</option>";
}
?>
</select>
<select name="mm" required>
<option value="">Month</option>
<?php
for($mm=01;$mm<=12;$mm++)
{
echo "<option value='$mm'>$mm</option>";
}
?>
</select>
<select name="yy" required>
<option value="">Year</option>
<?php
for($yy=2004;$yy>=1980;$yy--)
{
echo "<option value='$yy'>$yy</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go">
</form>
</body>
</html>
No comments:
Post a Comment