Age calculation in MySQL InnoDB database
When the date format stored in the MySQL database is dd-mm-yyyy, calculating age requires some specific steps.
Directly subtract the stored date of birth from the current date (using the TIMESTAMPDIFF
function), and the result is not in an easy-to-understand age format.
To calculate age from the returned results, follow these steps:
TIMESTAMPDIFF(YEAR, birthdate, CURDATE())
to extract the year number. This will give the total number of years the person lived. With these steps, you can calculate someone's age from their date of birth stored in dd-mm-yyyy format in a MySQL InnoDB database.
The above is the detailed content of How Can I Calculate Age from a Date of Birth Stored in MySQL InnoDB?. For more information, please follow other related articles on the PHP Chinese website!