Incorrect DOTW on SQL Server 8.0

  • After noticing some of the wrong days were missing information from my SQL server, I checked the DOTW that it current shows, and it has today (June 1, 2004) showing as Wednesday, not Tuesday.

    Is there a setting to change this?  The PC that SQL is running on has the correct date, time, etc?

    Any help would be great.

    Thanks,

    Kevin

     

  • The first thing I would do is go to Control Panel | Date/Time and make sure the date, time, and year are correct. Also, make sure you've got the correct time zone selected.

     

  • Depending on how you are getting the value for the day of week, the datefirst function, which sets the first day of the week,  could be affecting it. Take a look at "set DATEFIRST" in BOL.

    Steve

  • Don't think that "DATEFIRST" should matter in this case. As the @@DATEFIRST value is changed, only the weekday numbers are changed as well. It doesn’t affect the number to name mapping.

     

    SET DATEFIRST 7 -- default, Sunday

    SELECT DATEPART(WEEKDAY, getdate()),DATENAME(WEEKDAY, getdate())

    The result will be 4, Wednesday

     

    SET DATEFIRST 1 -- Monday

    SELECT DATEPART(WEEKDAY, getdate()),DATENAME(WEEKDAY, getdate())

    The result will be 3, still Wednesday

     

    As noted before, I would check the settings in the Control panel –especially for the correct time zone

  • Thats why I said "Depending on how you are getting the value for the day of week"...

    Try this...

    declare

    @date  datetime,

    @day_txt varchar(9),

    @day_num tinyint

    set @date = getdate()

    set datefirst 7

    select @day_num = datepart(dw, @date)

    select @day_txt =

       case

     when @day_num = 1 then 'Sunday'

     when @day_num = 2 then 'Monday'

     when @day_num = 3 then 'Tuesday'

     when @day_num = 4 then 'Wednesday'

     when @day_num = 5 then 'Thursday'

     when @day_num = 6 then 'Friday'

     when @day_num = 7 then 'Saturday'

       end

    select @day_num, @day_txt

    set datefirst 6

    select @day_num = datepart(dw, @date)

    select @day_txt =

       case

     when @day_num = 1 then 'Sunday'

     when @day_num = 2 then 'Monday'

     when @day_num = 3 then 'Tuesday'

     when @day_num = 4 then 'Wednesday'

     when @day_num = 5 then 'Thursday'

     when @day_num = 6 then 'Friday'

     when @day_num = 7 then 'Saturday'

       end

    select @day_num, @day_txt

     

    -- This is the body of a stored proc that I wrote before I knew about

    -- SELECT DATEPART(WEEKDAY, getdate()),DATENAME(WEEKDAY, getdate())

    -- Steve

  • Thanks guys.  I'm not quite sure what happened, but when I stopped the instance of SQL server, and restarted it again, the date was correct....kinda strange..!!

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

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