See String date and time formats in Microsoft TechNet.
You can use SQL Standard SQL date format. According to the link above, it is referred to as "multilingual":
insert into table1(approvaldate) values ('2012-06-18 10:34:09')
However, this will not work in all languages. For example, here is a quick script that uses dynamic SQL to test the date format in all SQL languages โโdefined in sys.syslanguages:
declare @sql nvarchar(4000) declare @LangID smallint declare @Alias sysname declare @MaxLangID smallint select @MaxLangID = max(langid) from sys.syslanguages set @LangID = 0 while @LangID <= @MaxLangID begin select @Alias = alias from sys.syslanguages where langid = @LangID if @Alias is not null begin begin try set @sql = N'declare @TestLang table (langdate datetime) set language ''' + @alias + N'''; insert into @TestLang (langdate) values (''2012-06-18 10:34:09'')' print 'Testing ' + @Alias exec sp_executesql @sql end try begin catch print 'Error in language ' + @Alias print ERROR_MESSAGE() end catch end select @LangID = min(langid) from sys.syslanguages where langid > @LangID end
If you run this script, you will get many errors, for example:
Danish error Converting a varchar data type to a datetime data type resulted in a value out of range.
A more language-independent choice for string literals is the international standard ISO 8601 . This format is very similar to the ANSI standard, with the exception of the letter "T" between date and time:
insert into @TestLang (langdate) values ('2012-06-18T10:34:09')
I tested this and it really works in all SQL languages.
Paul Williams Oct 18 2018-12-18T00: 00Z
source share