Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 198633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:57:15+00:00 2026-05-11T16:57:15+00:00

I need Week-Start-Date and Week-End-Date for particular Week number in a year (vb.net or

  • 0

I need Week-Start-Date and Week-End-Date for particular Week number in a year (vb.net or SQL Server)

For example, if weeknumber=1 and year 2009, I should get:

StartDate=1/1/2009
EndDate=1/3/2009

if weeknumber=2 and year 2009, then:

StartDate=1/4/2009
EndDate=1/10/2009

Actually I got week number by using datepart(wk, Date) in Query then I grouped by week number. Now I need start date and End Date for the grouped Week Number.

—
Raheel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:57:15+00:00Added an answer on May 11, 2026 at 4:57 pm

    TRY THIS TSQL:

    DECLARE @Year int
    DECLARE @WeekNo int
    SET @Year = 2009
    SET @WeekNo = 1
    
    DECLARE @DaysInWeekOne int
    DECLARE @FirstOfJan smalldatetime
    DECLARE @ThirtyFirstOfDec smalldatetime
    DECLARE @StartDateDayOfYear int
    DECLARE @EndDateDayOfYear int
    
    --GET THE START AND END OF THE YEAR
    SELECT
        @ThirtyFirstOfDec = Cast(('12/31/' + Cast(@Year as varchar)) as smalldatetime)
    ,   @FirstOfJan = Cast(('01/01/' + Cast(@Year as varchar)) as smalldatetime)
    
    --GET THE AMOUNT OF DAYS IN WEEK ONE
    SELECT
        @DaysInWeekOne = 7 - (DatePart(dw, @FirstOfJan) - 1)
    
    --GET THE START AND END DAYOFYEAR VALUES FOR THE GIVEN WEEK
    SELECT
        @StartDateDayOfYear = CASE WHEN ((@WeekNo-1)*7)-(7-@DaysInWeekOne) < 0 THEN 0 ELSE ((@WeekNo-1)*7)-(7-@DaysInWeekOne) END
    ,   @EndDateDayOfYear = ((@WeekNo-1)*7)-(7-@DaysInWeekOne) + 6
    
    --SELECT THE START DATE AND END DATE MAKING SURE IF THE COUNT RUNS OVER THE YEAR THAT WE SHOW THE 31/12
    SELECT
        @Year As mYear
    ,   @WeekNo As WeekNo
    ,   dateadd(dd, @StartDateDayOfYear, (@FirstOfJan)) As StartDate
    ,   CASE 
            WHEN dateadd(dd, @EndDateDayOfYear,   (@FirstOfJan)) > @ThirtyFirstOfDec THEN @ThirtyFirstOfDec 
            ELSE dateadd(dd, @EndDateDayOfYear, @FirstOfJan) 
        END As EndDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need mySQL timestamp for start of current week or any given date, if
I have two datetime objects; a start date and an end date. I need
Is there a way to get the date start/end for each week in PHP
I need to generate a report as follow: week-ending date | number of active
I need help getting the this week full date range in the following format:
Hallo all. if i have week number 42 and i need to know what
I need to output the days of the week in a JSP. Clearly I
I need to upgrade my current version of DNN this week. I am currently
I need to loop through each day of the week (monday tues...) and compare
How can I set a date range value for each week that gets updated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.