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

Posted on 2008-11-17
Last Modified: 2012-05-05

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.

Question by:oxyoo
    LVL 39

    Expert Comment

    by:Pratima Pharande
    LVL 14

    Accepted Solution

    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
    LVL 10

    Author Closing Comment

    Exactly what I needed, many thanks!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now