tags:

views:

21

answers:

1

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 = 1 and 01/10/2010 to 01/16/2010 returns to 2.. up to 53 weeks..

+2  A: 

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
LittleBobbyTables
i see.. its just simple logic.. but i can get it so easily. i spend 10 hours to solve it but i cant get it.. hayz.. thx.. littlebobbyTables
mapet