Salve a tutti, avrei bisogno di un aiutino con un codice...
nel mio sito ho bisogno di calcolare l'età anagrafica (precisa fino al giorno) partendo dal codice fiscale.....
io sono riuscito ad ottenere la data di nascita in formato gg/mm/aaaa, ma adesso...dalla data come faccio ad ottenere l'età?
codice sulla prima pagina:
Codice:
<script type="text/javascript">
function getDataByCF(cf) {
var tabellamesi = {
"A" : "01",
"B" : "02",
"C" : "03",
"D" : "04",
"E" : "05",
"H" : "06",
"L" : "07",
"M" : "08",
"P" : "09",
"R" : "10",
"S" : "11",
"T" : "12"
};
return cf.replace(/^(?:\w{6})(\d{2})(\w)(\d{2}).+$/, function(data, aa, mm, gg) {
var anno = parseInt(aa, 10);
var secolo = (anno < 9)? '20':'19';
anno = [secolo, aa].join('');
var giorno = parseInt(gg, 10);
var sesso = (giorno > 31)? 'F' : 'M';
if (sesso === 'F') giorno -= 40;
var mese = mm.toUpperCase();
mese = tabellamesi[mese];
return [giorno, mese, anno].join("/");
});
};
</script>
Codice HTML:
<form name="form" action="echo.php" method="post">
<p>CF
<input type="text" name="cf"
onblur="document.getElementById('nato').value = getDataByCF(this.value);"
onkeyup="this.value = this.value.toUpperCase();"/>
Nato <input name="nato" type="text" id="nato" readonly="readonly"/>
</p>
<p>
<input type="submit" name="submit" value="EFFETTUA IL LOGIN!" />
</p>
</form>
CODICE DELLA SECONDA PAGINA (INTERROGAZIONE)
Codice PHP:
<?php
session_start();
$codicefiscale=$_POST['cf'];
$data_nascita=$_POST['nato'];
echo $codicefiscale;
echo"<br>";
echo $data_nascita;
?>
<?php