我想计算从这个人出生到今天的年数.我有要使用的组件,但不知道如何使用它们.
I want to count the amount of years from a the year the person is born to today. I have the components to use but dont know how to use them.
SELECT COLUMN1, COLUMN2, DATEPART(YY,GETDATE()),
CONVERT(INT,+19)))LEFT(TABLE.COLUMN,2)
我想用 +19 在出生年之前显示它.例如,在数据库中,出生年份显示为 YY 而不是 YYYY.这就是为什么我要添加 19,所以 SQL 将计算从 19YY 到 2013 的年数.
I want to use the +19 to show it before the birtyear. Example in the database the birthyear is showed as YY not YYYY. That is why I want to add the 19, so the SQL will count years from 19YY to 2013.
试试这个
SELECT id
, Name
, DATEDIFF(yy, CONVERT(DATETIME, DOB), GETDATE()) AS AGE
, DOB
FROM MyTable
这篇关于从某个日期开始计算年数 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!