Select Date Based On Week

  • Scenario:

    ClosingWeek (table name)

    Date (column)

    2008-04-21

    2008-04-28

    2008-04-01

    2008-04-07

    2008-04-14

    Declare @date datetime

    Set @date = '2008-04-18'

    Need to select the date in table (Closingweek) where 04-18 falls under.

    So based on the above example 04-18 will fall under week 2008-04-14.

    04-23 will fall under 2008-04-21

    Hope this makes sense

    Any ideas on how to effectively select this date from the above table?

    Any information will be greatly appreciated.

  • Look at DATEPART with the wk option.

  • The function on this link should give you what you want.

    Start of Week Function:

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47307

    select

    Date,

    [Week stating Monday] =

    dateadd(dd,(datediff(dd,-53690,a.DATE)/7)*7,-53690)

    from

    MyTable a

Viewing 3 posts - 1 through 2 (of 2 total)

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