我有一个问题如何设置我想要的日期部分确切日期:她的例子代码:
SET DATEFIRST 7;
select CAST(DATEPART(wk, '01/03/2010') AS CHAR(4)).. // 01/01/2010 to 01/03/2010 to return 1
我如何设置datepart如果01/03/2010到01/09/2010返回= 1并且01/10/2010到01/16/2010返回到2 ..最多53周..
答案 0 :(得分:2)
从datepart中减去一个:
SET DATEFIRST 7;
select CAST(DATEPART(wk, '01/03/2010') - 1 AS CHAR(4))
select CAST(DATEPART(wk, '01/09/2010') - 1 AS CHAR(4))
select CAST(DATEPART(wk, '01/10/2010') - 1 AS CHAR(4))
select CAST(DATEPART(wk, '01/16/2010') - 1 AS CHAR(4))
结果:
1
1
2
2