Mysql
 sql >> Database >  >> RDS >> Mysql

Calcola l'età in base alla data di nascita

PHP

# object oriented
$from = new DateTime('1970-02-01');
$to   = new DateTime('today');
echo $from->diff($to)->y;

# procedural
echo date_diff(date_create('1970-02-01'), date_create('today'))->y;

demo

MySQL

SELECT TIMESTAMPDIFF(YEAR, '1970-02-01', CURDATE()) AS age

demo