首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

如何才能得到正确的“年”的差值

2012-01-03 
怎么才能得到正确的“年”的差值系统时间减去某一日期,得到年份的差值,比如2007-4-17减去2006-4-19的年份差

怎么才能得到正确的“年”的差值
系统时间减去某一日期,得到年份的差值,比如2007-4-17减去2006-4-19的年份差值为0

[解决办法]
declare @start datetime,@end datetime
select @start= '2006-4-19 ',@end= '2007-4-17 '
select datediff(year, '1900-01-01 ',@end-@start)

相差年
-----------
0

(1 行受影响)

declare @start datetime,@end datetime
select @start= '2006-4-19 ',@end= '2007-4-19 '--改为19
select [相差年]=datediff(year, '1900-01-01 ',@end-@start)

相差年
-----------
1

(1 行受影响)

热点排行
Bad Request.