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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:55:25+00:00 2026-05-25T11:55:25+00:00

In SQL Server 2008 the isoweek can be found with this: SELECT datepart(iso_week, getdate())

  • 0

In SQL Server 2008 the isoweek can be found with this:

SELECT datepart(iso_week, getdate())

Before SQL Server 2008 there were no built-in function to find isoweek.

I have been searching high and low for a good syntax to find a userdefined iso_week for SQL Server 2005. I found quite a few solutions. Didn’t like any of the solutions I found, most of them didn’t work, and they were way too long.

Since the issue is very old, I would expect this issue is depleted and the best solution has been found. I was unable to find a good method though.

I wrote a solution, which I am going to post later. But before I do, I want to make absolutely sure that no one else can match the solution I wrote.

I am hoping to earn the self-learner badge. I urge people to find the best answers out there for this ancient question.

I am going to post my answer after giving people a chance of finding a good solution.

  • 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-25T11:55:25+00:00Added an answer on May 25, 2026 at 11:55 am

    Here’s an approach that is similar to yours in that it also relies on this week’s Thursday. But in the end it uses the date differently.

    1. Get the date of this (ISO) week’s Thursday.

      Your own solution uses the hard coded date of a known Thursday. Alternatively, this week’s Thursday could be found with the help of @@DATEFIRST:

      SELECT Th = DATEADD(DAY, 3 - (DATEPART(WEEKDAY, @date) + @@DATEFIRST - 2) % 7, @date)
      

      (I wasn’t struggling too much for the right formula because it was already known to me.)

    2. Get the Thursday’s day of year:

      SELECT DY = DATEPART(DAYOFYEAR, Th)
      
    3. Use the number to find out the week like this:

      SELECT ISOWeek = (DY - 1) / 7 + 1
      

    Here are the above calculations in a single statement:

    SELECT ISOWeek = (DATEPART(DAYOFYEAR, Th) - 1) / 7 + 1
    FROM (
      SELECT Th = DATEADD(DAY, 3 - (DATEPART(WEEKDAY, @date) + @@DATEFIRST - 2) % 7, @date)
    ) s;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DB: Sql Server 2008. I have a really (fake) groovy query like this:- SELECT
On SQL Server 2008 R2, I have following T-SQL code: SELECT CAST(GETDATE() AS DATETIMEOFFSET);
Using SQL Server 2008, I need to select this XML into a Table. I
In sql server 2008, I have the following query: select c.title as categorytitle, s.title
Sql Server 2008 R2 Express. NHibernate 2.1.2.4. I get SQL like: SELECT customer0_.Id as
SQL Server 2008. I have this very large query which has a high cost
In SQL Server 2008, we can define a table type and use it as
Given SQL Server 2008, I have written a simple find in string function as
In SQL Server 2008, the following query works fine: WITH T AS ( SELECT
In sql server 2008, I am using a pattern like this: begin transaction begin

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.