Home > Database > Mysql Tutorial > How Can I Calculate Age from a Date of Birth Stored in MySQL InnoDB?

How Can I Calculate Age from a Date of Birth Stored in MySQL InnoDB?

Linda Hamilton
Release: 2025-01-16 11:42:29
Original
195 people have browsed it

How Can I Calculate Age from a Date of Birth Stored in MySQL InnoDB?

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:

  1. Use TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) to extract the year number. This will give the total number of years the person lived.
  2. Divide the result by 365.25 to convert years to days.
  3. Divide the result by 30.44 to convert days to months.

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!

source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template