Home mysql How to calculate age from date of birth column in mysql?

How to calculate age from date of birth column in mysql?

by Shahriar Sagor

Today now in this post i will show you How to calculate age from date of birth column in mysql? Sometimes, we need to calculate age from the birthdate by using mysql select query, you can do this in programming as like php,.net and etc framework but if you can do it by using mysql query. Now in the bellow example for mysql query we can learn to how to get the age from date field. We easily can get the age value from date by using mysql DATEDIFF().

So, let’s see the bellow query.

Example:
SELECT 
	id,
	(DATEDIFF(CURRENT_DATE, STR_TO_DATE(born_date, '%Y-%m-%d'))/365) as age 

FROM `users`

Read Also : Laravel 8 Mobile Number Verification Tutorial

Thanks for read. I hope it help you. For more you can follow us on facebook

close

You may also like