• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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