计算两个时间的年月(急求)
例如: '2004-03-13 '到今天 一共過去哪几年零几月
------解决方案--------------------select cast(datediff(year, '2004-03-13 ',getdate()) as varchar)+ '年 '+cast(datediff(month, '2004-03-13 ',getdate())/24 as varchar)+ '月 '
------解决方案--------------------修正一下:
select cast(datediff(year, '2004-03-13 ',getdate()) as varchar)+ '年 '+cast(datediff(month, '2004-03-13 ',getdate())%12 as varchar)+ '月 '
------解决方案--------------------这样可以解决结果为整年时显示xx年0月的问题:
select cast(datediff(year, '2004-03-13 ',getdate()) as varchar)+ '年 '+case when datediff(month, '2004-03-13 ',getdate())%12 > 0 then cast(datediff(month, '2004-03-13 ',getdate())%12 as varchar)+ '月 ' else ' ' end
------解决方案--------------------select cast(datediff(year, '2004-03-13 ',getdate()) as varchar)+ '年 '+cast(datediff(month, '2004-03-13 ',getdate())%12 as varchar)+ '月 '
------解决方案--------------------sdhylj(青锋-SS) zq
------解决方案--------------------select cast(datediff(year, '2004-03-13 ',getdate()) as varchar)+ '年 '+cast(datediff(month, '2004-03-13 ',getdate())%12 as varchar)+ '月 '
------解决方案--------------------select datediff(mm, '2005-04-04 ',getdate())/12 +‘年’+ datediff(mm, '2005-04-04 ',getdate())%12+‘月’
------解决方案--------------------select cast(datediff(mm, '2005-04-04 ',getdate())/12 as varchar) +‘年’+ cast(datediff(mm, '2005-04-04 ',getdate())%12 as varchar)+‘月’