Is Sunday or Tuesday your number 1?

  • When I run the following script:

    declare @d datetime

    set DATEFIRST 1 --first day of the week is sunday, monday is 2 etc etc

     

    select @d = '3/31/2005'

    select @d

    select datepart(dw, @d)

    select datename(dw, @d)

     

    I get :

    4

    Thursday

     

    But I thought Thursday was number 5 ??????

    can anyone explain

  • According to BOL, Monday is 1, so the results you're getting are correct.

    ValueFirst day of the week is
    1Monday
    2Tuesday
    3Wednesday
    4Thursday
    5Friday
    6Saturday
    7 (default, U.S. English)Sunday

    If you want Thursday to be 5, then  SET DATEFIRST 7   (Making Sunday the first day of the week)

  • SET DATEFIRST 1 makes Monday the first day of the week.  SET DATEFIRST 7 makes Sunday the first day of the week. 

    From BOL:

    SET DATEFIRST

    Sets the first day of the week to a number from 1 through 7.

    Syntax

    SET DATEFIRST { number | @number_var }

    Arguments

    number | @number_var

    Is an integer indicating the first day of the week, and can be one of these values.

    ValueFirst day of the week is
    1Monday
    2Tuesday
    3Wednesday
    4Thursday
    5Friday
    6Saturday
    7 (default, U.S. English)Sunday

    Greg

    Greg

  • thanks.

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

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