How to Calculate Age From Date Of Birth In Mysql

How to Calculate Age From Date Of Birth In Mysql
Written by Thomas Brown

We calculate our age by the difference in full years between our current date and our date of birth. This number indicates the age at which we finished. The age when we start to get a day is one more than that.

In this post we will learn how to calculate age from date of birth in mysql. We can calculate diferent ways. We must use date functions for this. We will use CurDate() function to learn current date, we’ll use year function to get year of a date and we’ll use TIMESTAMPDIFF function to get difference of two year. We’ll write example queries from the library database.

This image has an empty alt attribute; its file name is libraryDatabase-1024x347.png
TO DOWNLOAD THE SAMPLE LİBRARY DATABASE CLICK

Example Queries

Example-1: List all students name, surname and age

Method -1

This method is not recommended because it usually produces 1 more value. It does not always produce accurate results.

Method-2

This method is the recommended method. It always gives accurate results.

Example-2: List all students name, surname and age sorted by their age

Example-3: List the name and surname of students whose age 17

Example-4: How old was the student named Alfie Watson when he has got the last book

In this post we have learned how to calculate age from date of birth in MYsql.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: