Home > Database > Mysql Tutorial > body text

How to calculate age from date of birth in MySQL?

PHPz
Release: 2023-09-18 16:21:08
forward
2235 people have browsed it

How to calculate age from date of birth in MySQL?

We can calculate the age from date of birth as follows -

mysql> SET @dob = '1984-01-17';
Query OK, 0 rows affected (0.00 sec)
Copy after login

The above query will pass the value "1984-01-17" in the "dob" variable ". Then after applying the formula in the query below we can get the age in years.

mysql> Select Date_format( From_Days( To_Days(Curdate()) - To_Days(@dob) ), '%Y' ) + 0 AS ‘Age in years;
+---------------+
| ‘Age in years’|
+---------------+
|   33          |
+---------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of How to calculate age from date of birth in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!