When a user registers on my site, their birth date is stored in a mysql database. I'm using the DATE
datatype for birth date.
How do I calculate the users current age?
When a user registers on my site, their birth date is stored in a mysql database. I'm using the DATE
datatype for birth date.
How do I calculate the users current age?
If you're looking for a PHP solution this works:
$today = new DateTime();
$birthdate = new DateTime("1973-04-18");
$interval = $today->diff($birthdate);
echo $interval->format('%y years');
You can use one of many date functions in both MySQL and PHP. MySQL example:
SELECT TIMESTAMPDIFF(YEAR,'1980-02-04',NOW()) AS age
Further reading: