• The reason for the difference is this:

    Datename and Datepart are require dates, in this case they are being given integers, which are being converted to dates. 

    7 is converted to 1900-01-08 00:00:00.000 (this happens to be a Monday), if you then take the datepart (day) of that its 8. 8 is converted to 1900-01-09 00:00:00.000, which happens to be a Tuesday.

    Here is some code to show what I am saying.

    declare @dtmTest datetime

    declare @dtmTest2 datetime

    set @dtmTest = 7

    set @dtmTest2 = datepart(d, @dtmTest)

    select @dtmTest, @dtmTest2, datename(dw, @dtmTest), datepart(d, @dtmTest), datename(dw, @dtmTest2)

    You will get :

    --------------------------- --------------------------- ------------------------------ ----------- ------------------------------

    1900-01-08 00:00:00.000     1900-01-09 00:00:00.000     Monday                         8           Tuesday

    (1 row(s) affected)

    I hope this helps,

    Chuck