如何在SQL Server 2008中找到月数,周数,天数的日期差异?

时间:2017-09-27 07:02:43

标签: sql sql-server

例如我需要

的日期差异

1.DECLARE @lDFROM DATE ='2016-12-01',@ lDTO DATE ='2018-05-31'

结果:

18 noofmnth,
0 nofweek,
0 noofdays

2.DECLARE @lDFROM DATE ='2016-12-31',@ lDTO DATE ='2018-05-25'

结果:

17 noofmnth,
3 nofweek,
4 noofdays

1 个答案:

答案 0 :(得分:0)

使用datediff

select DATEDIFF(wk,'2016-12-01','2018-05-31')+1