Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Datetime issues. American vs. British?

On my test DB, the dates are displayed in a DD/MM/YYYY format. By displayed I mean when you right click, open table in Management Studio, the returned data are displayed in a DD/MM/YYYY format.

Funny thing is, when I write T-SQL to retrieve records, I have to input a MM/DD/YYYY format to get back the right data. Is there anyway I can align this to a DD/MM/YYYY format?

like image 430
super9 Avatar asked Jul 27 '09 08:07

super9


1 Answers

You can use SET LANGUAGE to choose the date format that SQL Server expects in queries (I think management studio uses client computer's regional settings for display purposes, not sure though). However, I suggest passing values using parameters instead of embedding them in query statement. You won't encounter any issues if you use parameters. Everything is taken care of.

set language us_english
declare @d datetime = '1929/12/18'

set language british
declare @d datetime = '1929/12/18' -- fails

To change the server default language:

declare @langid int = (select langid from syslanguages where name = 'british')
exec sp_configure 'default language', @langid
reconfigure with override
like image 151
mmx Avatar answered Sep 27 '22 16:09

mmx