SQL Server Datetime issues. American vs. British?

super9 picture super9 · Jul 27, 2009 · Viewed 20.8k times · Source

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?

Answer

mmx picture mmx · Jul 27, 2009

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