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

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

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

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →