Friday, February 24, 2012

DatePart problem

Can anyone explain me why this query

SELECT DATEPART(dw, CONVERT(DATETIME, '2001-01-25 01:00:00', 120))

returns 5 on one SQLServer, and 4 on another one. It cannot be a regional settings problem because 25 could never be a month. Any way, is there a deterministic way to create a DATE regardless of the server's regional settings?

I mean, I have the year, month and day... how do I tell the server "This is the year; This is the month; This is the day... convert this into a DATE, and the tell me which day of the week is"??

TIA,I think I've figured it out... I'll post again if I need further help.|||And the solution was? *curious*|||I'll bet on SET DATFIRST (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_set-set_4qic.asp).

-PatP|||I'll bet on SET DATFIRST (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_set-set_4qic.asp).

-PatPGood bet! You were right. That was the solution I had found out.

No comments:

Post a Comment