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 6974533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:15:00+00:00 2026-05-27T17:15:00+00:00

Our business considers a week from (Monday – Sunday). I need to write a

  • 0

Our business considers a week from (Monday – Sunday). I need to write a T-SQL function, which passes in year, week no as parameters and it will return the start and end date of that week. However I’ve seen many examples but the problem lies within the year overlapping.

e.g December 26, 2011 (Monday) – January 01, 2012 (Sunday)… << Would want to consider this as the last week of 2011.

And also in T-SQL the datepart(ww,DATE) considers Sunday as the start of the week??

Or Am I better creating my own table with the week no and storing its start and end date?

  • 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-27T17:15:00+00:00Added an answer on May 27, 2026 at 5:15 pm
    DECLARE
        @Year INT,
        @Week INT,
        @FirstDayOfYear DATETIME,
        @FirstMondayOfYear DATETIME,
        @StartDate DATETIME,
        @EndDate DATETIME
    
    SET @Year = 2011
    SET @Week = 52
    
    -- Get the first day of the provided year.
    SET @FirstDayOfYear = CAST('1/1/' + CAST(@YEAR AS VARCHAR) AS DATETIME)
    
    -- Get the first monday of the year, then add the number of weeks.
    SET @FirstMondayOfYear = DATEADD(WEEK, DATEDIFF(WEEK, 0, DATEADD(DAY, 6 - DATEPART(DAY, @FirstDayOfYear), @FirstDayOfYear)), 0)
    
    SET @StartDate = DATEADD(WEEK, @Week - 1, @FirstMondayOfYear)
    
    -- Set the end date to one week past the start date.
    SET @EndDate = DATEADD(WEEK, 1, @StartDate)
    
    SELECT @StartDate AS StartDate, DATEADD(SECOND, -1, @EndDate) AS EndDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our business sends a newsletter to a vast number of subscribers every week. When
I've been asked to write an internal application for our business that uses mapping
Okay, so we have a utility here in-house that generates business-model classes from our
i am interested in creating a setup tool for our business application which is
The company where I work created this application which is core to our business
Our business deals with houses and over the years we have created several business
Our business currently has an online store and recently we've been offering free specials
In one facet of our business, we offer individuals the ability to sell products
In our .Net application, some of our business objects use lazy loading to access
Our current project has ran into a circular dependency issue. Our business logic assembly

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.