DateDiff(day/month/year/second/hour/minutes,startdate,enddate)
select Datediff(day,cast("2010-01-01" as datetime),getdate())//返回2010-01-01与当前时间相差的天数
select Datediff(month,cast("2010-01-01" as datetime),getdate())//返回2010-01-01与当前时间相差的月数
select Datediff(year,cast("2010-01-01" as datetime),getdate())//返回2010-01-01与当前时间相差的年数
从此可以看出第一个参数是enddate 与startdate相差的时间的计量单位;另:第二个转换时间的参数也可以写为CONVERT(datetime,'2010-01-01')
|