本文介绍了MySQL的日期差异来计算年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于 datediff
MYSQL功能的问题,我可以使用它,它很简单。但是我不明白如何使用它来收集表格中的差异。例如
我有一个列 dob
,我想编写一个将执行类似
select dateDiff(current_timeStamp,dob)
之间的差异,每个查询结果是差异,用户的年龄。
from sometable'here dob is the table column
dob解决方案你的意思是这样吗?
SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),dob)),%Y)+ 0 AS age from sometable
()
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 likeselect 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.解决方案You mean like this?
SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), dob)), "%Y")+0 AS age from sometable
(Source)
这篇关于MySQL的日期差异来计算年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!