Get Date based on a weeknumber

 

horizontal rule

Back Home Next

Author Stefan Goebel
Date 28-09-2000

 

To get the first day of a given weeknumber, you can code the following:

 

Declare   @Year smallint, @Week tinyint
Select    @Year = 2000
Select    @Week = 38

Select    DateAdd( dd, ( @Week - 1 ) * 7 + ( ( 9 - DatePart( weekday, '1.1.' +
             Convert( varchar, Year ) ) ) % 7 ), '1.1.' + Convert( varchar, @Year ) )


The tricky part is to get the day on which the calendar year starts, which is achieved by this :

 

( ( 9 - DatePart( weekday, '1.1.' + Convert( varchar, @Year ) ) ) % 7 ) + 1