Date Difference in MySQL to calculate age

2020-02-10 07:04发布

I have a problem regarding the datediff MYSQL function, I can use it and it is simple. But I don't understand how to use it to collect differences within the table field. E.g.

I have a column dob and I want to write a query that will do something like

select dateDiff(current_timeStamp,dob) 
from sometable 'here dob is the table column

I mean I want the difference from the current date time to the table field dob, each query result is the difference, the age of the user.

7条回答
家丑人穷心不美
2楼-- · 2020-02-10 07:45

You could do this

SELECT TIMESTAMPDIFF(YEAR, date_of_birth, NOW()) ASageFROM your_table

Works everytime.

查看更多
登录 后发表回答