How to Create a page in PHP with a date input field. In this field you choose A (birth) date. And also A submit button. With this button you give the browser dialog Age in years, months and days prelative to the system date.
Asked
Active
Viewed 2,799 times
1 Answers
0
Try This Code
<?php
if(isset($_POST['age'])){
$dob = $_POST['age'];
calculate_age($dob);
$year = calculate_Year($dob);
}
function calculate_age($birthday)
{
$today = new DateTime();
$diff = $today->diff(new DateTime($birthday));
return printf('%d years, %d month, %d days', $diff->y, $diff->m, $diff->d);
}
function calculate_Year($birthday)
{
$today = new DateTime();
$diff = $today->diff(new DateTime($birthday));
return $diff->y;
}
?>
<form method="post" action="age.php" >
ENTER DATE OF BIRTH : <input type="date" name="age" />
<input type="submit" value="Calculate Age" />
</form>
<?php if($year > 20)
{?>
<img src="old_image.png" />
<?php }else{?>
<img src="young_image.png" />
<?php } ?>

Ehsan Ilahi
- 298
- 5
- 15
-
this is good, and now i wanna show a photo after submit how do i do that? – Joey Feb 17 '17 at 10:36
-
like if you are young, photo with young people, if you are old, photo with ould people – Joey Feb 17 '17 at 10:37
-
-
i dont understand this php, thats why i asked.. you know how to delete the value day month en days after the submit – Joey Feb 17 '17 at 10:57
-