forked from tutsmake/php-age-calculator-source-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp-age-calculator.php
More file actions
99 lines (82 loc) · 1.92 KB
/
Copy pathphp-age-calculator.php
File metadata and controls
99 lines (82 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<head>
<title>PHP Age Calculator | Tutsmake.com</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="card">
<div class="card-header">
PHP Age Calculator
</div>
<div class="card-body">
<form action="php-age-calculater.php" method="post" class="form-group">
<div class="row mb-3">
<div class="col-md-4">
<select name="day" class="form-control">
<?php
for($i=1;$i<=31;$i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
</div>
<div class="col-md-4">
<select name="month" class="form-control">
<?php
for($i=1;$i<=12;$i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
</div>
<div class="col-md-4">
<select name="year" class="form-control">
<?php $year = date('Y'); ?>
<?php
for($i=1900;$i<=$year;$i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
</div>
</div>
<div class="row">
<div class="col-md-4">
<input type="submit" name="submit" class="btn btn-primary " value="Click to calculate age">
</div>
</div>
</form>
</div>
<div class="card-footer">
<?php
if(isset($_POST['submit'])) {
$day=$_POST['day'];
$month=$_POST['month'];
$year=$_POST['year'];
$dob=$day.'-'.$month.'-'.$year;
$bday=new DateTime($dob);
$age=$bday->diff(new DateTime);
$today=date('d-m-Y');
echo '<br />';
echo '<b>Your Birth date: </b>';
echo $dob;
echo '<br>';
echo '<b>Your Age : </b> ';
echo $age->y;
echo ' Years, ';
echo $age->m;
echo ' Months, ';
echo $age->d;
echo ' Days';
}
?>
</div>
</div>
</div>
</body>
</html>