本文介绍了MySQL的日期差异来计算年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于 datediff MYSQL功能的问题,我可以使用它,它很简单。但是我不明白如何使用它来收集表格中的差异。例如
我有一个列 dob ,我想编写一个将执行类似
select dateDiff(current_timeStamp,dob) from sometable'here dob is the table column 解决方案你的意思是这样吗?
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 like
select dateDiff(current_timeStamp,dob) from sometable 'here dob is the table columnI 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的日期差异来计算年龄
发布评论