Query question

  • Quick question.  How do I specify my date range to only pull up days Monday - Wednesday?

     

    I am new, i think I should use dateadd()

     

     

    please help

  • have a look at datepart()


    * Noel

  • Can you please include the syntax?

  • select *

    from [your table]

    where datepart(dw, [yourdatecolumn]) in (1,2,3)


    * Noel

  • Thanks Noel

     

    my hero

  • I thought Monday to Wednesday were (2, 3, 4)

     


    N 56°04'39.16"
    E 12°55'05.25"

  • Not necessarily (could be 4, 5, 6 also)

    Since it's depending on the setting of @@DATEFIRST (which may change/be different), the 'safe' way would be:

    select ( @@datefirst + datepart(weekday, <supply date here> ) -2 ) %7 + 1

    Then no matter of what setting @@DATEFIRST has, monday will aways be 1.

    /Kenneth

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

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