[color=red]------------convert日期转成字符串[/color]select getdate()
select [color=red]convert[/color](char(8),getdate(),112)
select convert(char(8),getdate(),108)
[color=red]--可以得到日期的部分值,[/color]
select year(getdate())
select datepart(yy,getdate())
select datepart(mm,getdate())
[color=red]--这样就可以得到两个年份的相差值
------字符串转成日期[/color]select year(getdate())-datepart(yy,[color=red]cast[/color]('1983-12-31' as datetime))
select [color=red]convert[/color](char(8),getdate(),112)
select convert(char(8),getdate(),108)
[color=red]--可以得到日期的部分值,[/color]
select year(getdate())
select datepart(yy,getdate())
select datepart(mm,getdate())
[color=red]--这样就可以得到两个年份的相差值
------字符串转成日期[/color]select year(getdate())-datepart(yy,[color=red]cast[/color]('1983-12-31' as datetime))