Can I change the default Dateformat in SQL Server 2005 ?
When I list all sys.syslanguages data, I can see that the dateformat for
French (langid = 2) is set to 'dmy' but I want to set it to 'ymd'.
I know that I can use SET DATEFORMAT YMD in my storeproc and I still know
that I can use Convert with my date but... I don't want to change all of my
existaing code.
Is this possible ?
Thanks
You can configure the default language, which also changes the default
date format, but you cannot configure the default date format without
changing the default language. So if you want to use the French
language, but the ymd date format, I see no other way than using SET
DATEFORMAT (in all your procedures or directly when you open the
connection).
Razvan
|||Directly when you open the connection ?
What you mean ? A kind of trigger ?
Regard
Vince
"Razvan Socol" wrote:
> You can configure the default language, which also changes the default
> date format, but you cannot configure the default date format without
> changing the default language. So if you want to use the French
> language, but the ymd date format, I see no other way than using SET
> DATEFORMAT (in all your procedures or directly when you open the
> connection).
> Razvan
>
|||Vincent Bernier wrote:
> Directly when you open the connection ?
> What you mean ? A kind of trigger ?
No. When you open the connection from your application, simply execute
a "SET DATEFORMAT ymd" (without any procedure or trigger). It should
remain in effect for all subsequent batches in the same connection,
unless another SET DATEFORMAT is encountered in your code.
If you execute SET DATEFORMAT in a procedure, it will remain in effect
for the scope of that procedure and the procedures/triggers called by
it, but it will be reset to the previous value when the procedure ends.
Using SET DATEFORMAT is not a very safe thing to do if you really
depend on that date format for specifying datetime values, so I
recommend that you use datetime constants specified in a neutral way
(which works regardless of the date format setting). See:
http://www.karaszi.com/SQLServer/info_datetime.asp
Razvan
|||Thank, the ref site will help me.
"Razvan Socol" wrote:
> Vincent Bernier wrote:
> No. When you open the connection from your application, simply execute
> a "SET DATEFORMAT ymd" (without any procedure or trigger). It should
> remain in effect for all subsequent batches in the same connection,
> unless another SET DATEFORMAT is encountered in your code.
> If you execute SET DATEFORMAT in a procedure, it will remain in effect
> for the scope of that procedure and the procedures/triggers called by
> it, but it will be reset to the previous value when the procedure ends.
> Using SET DATEFORMAT is not a very safe thing to do if you really
> depend on that date format for specifying datetime values, so I
> recommend that you use datetime constants specified in a neutral way
> (which works regardless of the date format setting). See:
> http://www.karaszi.com/SQLServer/info_datetime.asp
> Razvan
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment