Friday, September 5, 2008

DayofWeek functions differently between SQL Servers?

A question this week on the forums that might be of interest involved a stored procedure having different results for the following query:

SELECT GETDATE() 'Today'
,convert(char(1),DATEPART(weekday, GETDATE()+6)) AS 'InDay_No'
,DATENAME(DW, GETDATE()+6) AS 'InDay_Name'
,convert(char(1),DATEPART(weekday, GETDATE()+2)) AS 'OutDay_No'
,DATENAME(DW, GETDATE()+2) AS 'OutDay_Name'


On one server the output for the day number was 2 for Tuesday while on another server it was 3.  This was caused by different default language settings for the login on the servers.  The @@Datefirst parameter will show the difference in configuration, and changing the default language resolves the problem.

No comments:

Post a Comment