find the first and last date of the week

  • Hi Guys,

    How to find first date and last date of the week in the given two dates?

    Please help me

    Thanks in advance.


    Kindest Regards,

    karthik

  • Hi Karthi,

    set

    datefirst 1

    Select

    getdate() - (datepart(dw,getdate())-1), getdate() + 7 - (datepart(dw,getdate()))

  • Edit: Nevermind.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • What day of the week do you consider the first day of the week to be?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • GilaMonster,

    How does your DateWeekEnds function work? Suppose I'm using the SQL Server 2000 defaults and @@DATEFIRST=7 (Sunday). If today is a Monday and I pass in today's date, the return value evaluates like:

    dateadd(day, 7 - 1 + 4, <today's date&gt or 10 days from today. Thanks for any insight you can provide.

    Steve


    Steve Eckhart

  • Apparently they don't.

    Sorry, I wrote those a while back and they did work then. Haven't used them in ages. Will check.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply