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.
| Author |
Topic |
|
jones_d
Yak Posting Veteran
61 Posts |
Posted - 2005-01-14 : 16:06:55
|
Hi,I am running the following sql against 2 databases:set dateformat ymdselect datepart(week,'2006-01-02 00:00:00') In 1 database I get 1 as the result. In the other I get 2 as the result. Since both databases are returning different results I assume that they are using different calendars.Does anyone know how I can find out what calendar SQL Server is using?Is it possible to change this? |
|
|
clarkbaker1964
Constraint Violating Yak Guru
428 Posts |
Posted - 2005-01-14 : 16:43:08
|
Or could the issue be related to the Language... mdy other languages say dmy check what the result is when you run somethin like 2006-01-31 versus 2006-31-01 |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-01-14 : 17:46:53
|
| see in bol SET DATEFIRST;obviously this option has different values in the two databases--- set datefirst 1 --- 2set dateformat ymdselect datepart(ww,'2006-01-02 00:00:00'), @@datefirst |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-01-15 : 09:01:51
|
1.On what depends how SS will interprete some string representation of a date(time)?2.Say, SS has received and has to "parse" the select: select datepart(ww,'2006-01-02')3.Note: it absolutely does not matter from where this select was sent to the SS.It might be QA, or some VB-ADO code or whatever you like.4.So, how SS should interprete '2006-01-02'? As Jan 02 or as Feb 01?5.The answer is: it depends ONLY on the default_language of the login under which theselect statement was issued.In QA, I (sa) check my personal settings:select @@datefirstselect @@language----7----------us_englishMeans, 'for me' Week begins on Sundays, and 'my' dateformat is mdy (or yyyymd).So, the result of select datepart(ww,'2006-01-02') will be:---1Now I want to change my preferences and I run this exec:exec sp_defaultlanguage 'sa', 'french'From now (after re-connecting) my settings (in all my sessions, in all availabledatabases) will be:select @@datefirstselect @@languageselect datepart(ww,'2006-01-02')----1----------french---6Of course, SET DATEFORMAT and SET DATEFIRST will still work for me but onlyduring one session.Note a special case of datetime strings without separators (/, -, .). SS ALWAYSinterpretes them as ymd. Exs: '20040131', '050131'.To see correspondence LANGUAGE - DATEFORMAT - DATEFIRST runselect langid, dateformat, datefirst, name from master..syslanguageslangid dateformat datefirst name ------ ---------- --------- ------------- 0 mdy 7 us_english1 dmy 1 Deutsch2 dmy 1 Francais3 ymd 7 ???4 dmy 1 Dansk5 dmy 1 Espanol6 dmy 1 Italiano7 dmy 1 Nederlands8 dmy 1 Norsk9 dmy 7 Portugues10 dmy 1 Suomi11 ymd 1 Svenska12 dmy 1 cestina13 ymd 1 magyar14 dmy 1 polski15 dmy 1 romana16 ymd 1 hrvatski17 dmy 1 slovencina18 dmy 1 slovenski19 dmy 1 ????????20 dmy 1 áúëãàðñêè21 dmy 1 ðóññêèé22 dmy 1 Turkce23 dmy 1 British |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-01-15 : 17:45:14
|
| 6.There is no such thing as DATEFORMAT & DATEFIRST for this or that given database.Suppose,I created the following view:use myDBGOcreate view vw as select datepart(ww,'31-01-2006')GOCan you tell is this view correct or not??? No, you can't. The question itself is incorrect.If language of my login is French then select * from vw will work fine for me,but if it's US_English then I will get an data type conversion error. |
 |
|
|
|
|
|
|
|