I'm trying to calculate the age of a person. The result should only show years and days.
For example, when I enter the date 20.05.2000, it prints out 21 years and 18 days...
Highly appreciate any good solutions, thanks.
The code:
<h3>Enter birthdate</h3>
<form name="date" method="POST">
<input type="date" name="birthdate"
placeholder="dd-mm-yyyy">
<input type="submit" name="submit" value="Submit">
</form>
<?PHP
$birthdate = new DateTime($_POST['birthdate']);
$today = new DateTime(date('d.m.y'));
$diff = $today->diff($birthdate);
if(isset($_POST['submit'])){
echo "Years: " .$diff->y.", and Days: " .$diff -> d;
}
?>