开发者

how to setup datepart set sql start date and end date

i had a problem how to set up the datepart exact date that i want: hers my example Code:

SET DATEFIRST 7;
select CAST(DATEPART(wk, '01/03/2010') AS CHAR(4)).. // 01/01/2010 to 01/03/2010 to return 1

how can i set the datepart if 01/03/2010 to 01/09/2010 returns开发者_如何学Go = 1 and 01/10/2010 to 01/16/2010 returns to 2.. up to 53 weeks..


Subtract one from the 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))

Results in:

1
1
2
2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜