Sarita Sharma
Sarita Sharma

Reputation: 253

How to calculate age based on date of birth in mysql?

My date of birth format is : 2017-Feb-15

when I am using the following query, it's not working

select (year(current_date)-year(dob)) as age from user 

or how to current 2017-Feb-15 into 2017-02-15 format

Upvotes: 1

Views: 5534

Answers (1)

skelwa
skelwa

Reputation: 585

You can use TIMESTAMPDIFF.

select TIMESTAMPDIFF(YEAR, str_to_date(dob, '%Y-%M-%d'), current_date) AS age
from user;

Upvotes: 1

Related Questions