• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 484
  • Last Modified:

How to get the start and end date for a year and week number, eg YYYYWW?

Hi,

I have an int that holds information about a year and week: YYYYWW, ex:
declare @currentweek int
set @currentweek = 200836

From this, how can I get the start and end date for this week?

PS: I would also like to specify if the week starts with sunday or monday.


Thanks!
0
oxyoo
Asked:
oxyoo
1 Solution
 
BinuthCommented:
declare @currentweek int
set @currentweek = 200801
declare @firstDayYear as datetime
set @firstDayYear = CAST('01/01/' + LEFT(@currentweek,4) AS DATETIME)
set @currentweek = RIGHT(@currentweek,2)
select dateadd(d,(((7*@currentweek)-datepart(dw,@firstDayYear))-6),@firstDayYear) as FirstDate
select dateadd(d,((7*@currentweek)-datepart(dw,@firstDayYear)),@firstDayYear) as lastDate
0
 
oxyooAuthor Commented:
Exactly what I needed, many thanks!!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now