How to get an age from a D.O.B field in MySQL?

后端 未结 13 1547
鱼传尺愫
鱼传尺愫 2020-11-29 07:01

I need to calculate the age of a \"customer\" from their date of birth.

I have tried to use the following:

DATEDIFF(year, customer.dob, \"2010

13条回答
  •  心在旅途
    2020-11-29 07:43

    DATE_FORMAT(FROM_DAYS(DATEDIFF(CURDATE(),'1869-10-02')), '%Y')+0 AS age;
    

    Above MySQL query has been tested and verified. It will give you exact age in years. I have taken this idea from Marcos answer and switched DATEDIFF() parameters.

提交回复
热议问题