1
This code calculates the difference between dates:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="">
<input type="DateTime" onblur="clicaBotao()" name="dn">
<input type="submit" id="buton" name="calcula" value="CALCULAR">
</form>
<script>
function clicaBotao() {
buton.click();
}
</script>
</body>
</html>
<?php
date_default_timezone_set('Europe/Lisbon');
$dn = new DateTime ($_POST['dn']);
$hoje = new DateTime(Date());
$idade = $hoje ->diff ($dn);
echo "Tem {$idade->y} anos e {$idade->m} meses de idade";
?>
After typing the birth date, when leaving the DateTime
the age is calculated.
Only that the Datetime field is deleted and I want it to remain, to be entered in the database. How can I get around this?
This your code gives a refresh on the page, you want to make the code to record in the bank in the same file that has the form? to fill the value just add value="<? php echo $_POST['Dn']? >" to the input
– AnthraxisBR
<input type="datetime"> Obsolete https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime
– user60252