Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 DATEPART - Returns incorrect day.

Author  Topic 

mlon
Starting Member

2 Posts

Posted - 2007-10-03 : 18:37:59
Hi,

I have 2 servers and when i run the folowing statement i get 2 different results.

select DATEPART(dw, '3/october/2007')

On the american server i get "4" returned and on the new zealand server i get "3" returned. I've checked the servers time and both look correct. Does anybody have any ideas why i would recieve 2 different values? I'm pretty sure "3" should be returned in both cases.


FYI....
american server time using getdate() - 2007-10-03 17:26:21.827
NZ server time using getdate() - 2007-10-04 11:28:43.533

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-10-03 : 18:50:55
It depends on the settings. From BOL:

quote:

The weekday (dw) datepart returns a number that corresponds to the day of the week, for example: Sunday = 1, Saturday = 7. The number produced by the weekday datepart depends on the value set by SET DATEFIRST. This sets the first day of the week.



I get 4 returned on two different servers running different timezones. My DATEFIRST is set to the default of Sunday.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

mlon
Starting Member

2 Posts

Posted - 2007-10-03 : 18:56:23
I didn't even realise this function existed. I have updated the DateFirst to be consistent across servers.

Thankyou!
Go to Top of Page
   

- Advertisement -