SQL determine WeekNo of a date.

Posted on 2011-05-03
Last Modified: 2012-05-11
I am looking to determine what week of the year a date falls in.
what I am running into is Sunday appears to be calculated as first day of the week
is there a way I can change this to Monday being first day of the week  as we search for transactions on the work week monday to sunday.

right now if i want to search for data 10 wks ago based on beginning and ending dates
ex: 04-25-2011 to 05-01-2011, 05-01-2011 is sunday and is a diff week no than 04-25-2011
Question by:schuitkds
    LVL 32

    Expert Comment


    select datename(week, getdate())
    LVL 32

    Expert Comment


    To change srtart of week to Monday you can use

    SET DATEFIRST 1  --Monday
    LVL 4

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now