In this tutorial we will see that, how to calculate age from date of birth column using mysql.
Many time we need to calculate age from date of birth, so we can do it using php, Laravel, codeigniter etc but here we will see how to calculate age from date of birth column using SQL Server DATEDIFF() Function.
Syntax –
DATEDIFF(interval, date1, date2)
Parameter values -
Parameter |
Description |
interval |
Required. The part to return. Can be one of the following values:
|
date1, date2 |
Required. The two dates to calculate the difference between |
Example for get age from date of birth column –
SELECT
Id,
(DATEDIFF(CURRENT_DATE,
STR_TO_DATE(born_date, ' %Y-%m-%d'))/365) as age FROM `users`