As a bit of a sidebar, it's pretty amazing how many languages deviate from the YYYY-MM-DD format for DATETIME and SMALLDATETIME formats even as late as SQL Server 2017. I don't know about 2019 because I've not downloaded it yet.
Here's some code that demonstrates what I and @jeffw8713 and I are talking about (if you want to run the code to see)...
--===== Environmental Presets
SET NOCOUNT ON;
SET LANGUAGE 'English';
--===== Drop the results table to make reruns in SSMS easier.
DROP TABLE IF EXISTS #Results
;
GO
--===== Create the test table.
CREATE TABLE #Results
(
DateTime DATETIME NOT NULL
,SmallDateTime SMALLDATETIME NOT NULL
,Date DATE NOT NULL
,DateTime2 DATETIME2(7) NOT NULL
,Alias NVARCHAR(256) NOT NULL
,Conversion VARCHAR(7) NOT NULL
)
;
--===== Brute force a PK using an index.
-- We don't want to use a CONSTRAINT on a Temp Table.
CREATE UNIQUE CLUSTERED INDEX PK_#Results ON #Results (Alias,Conversion)
;
GO
--===== Declare and preset some obviously named variables.
DECLARE @DateString NCHAR(10) = N'2020-07-12' --YYYY-MM-DD intended
,@SQL NVARCHAR(MAX) = ''
;
--===== Create the test SQL.
-- It creates one of the following for each language alias.
-- Basically, it populates the results table using the various default conversions
-- of @DateString.
SELECT @SQL += REPLACE(REPLACE(REPLACE(N'
SET LANGUAGE <<Alias>>
;
INSERT INTO #Results WITH (TABLOCK)
(
DateTime
,SmallDateTime
,Date
,DateTime2
,Alias
,Conversion
)
SELECT DateTime = CAST(<<@DateString>> AS DATETIME )
,SmallDateTime = CAST(<<@DateString>> AS SMALLDATETIME)
,Date = CAST(<<@DateString>> AS DATE )
,DateTime2 = CAST(<<@DateString>> AS DATETIME2 )
,Alias = <<Alias>>
,Conversion = "CAST"
UNION
SELECT DateTime = CONVERT(DATETIME ,<<@DateString>>)
,SmallDateTime = CONVERT(SMALLDATETIME,<<@DateString>>)
,Date = CONVERT(DATE ,<<@DateString>>)
,DateTime2 = CONVERT(DATETIME2 ,<<@DateString>>)
,Alias = <<Alias>>
,Conversion = "CONVERT"
;' --Other end of REPLACEs
,'"','''')
,'<<Alias>>',QUOTENAME(Alias,''''))
,'<<@DateString>>',QUOTENAME(@DateString,''''))
FROM sys.syslanguages
ORDER BY Alias
;
--===== Run the dynamic SQL we created
--PRINT @SQL;
EXEC (@SQL)
;
--===== Make sure we're back in the English language
SET LANGUAGE 'English'
;
--===== Let's see what is "broken" and what is not.
SELECT *
,IsDateTimeBroken = IIF(DateTime <> @DateString,'Yes','')
,IsSmallDateTimeBroken = IIF(SmallDateTime <> @DateString,'Yes','')
,IsDateBroken = IIF(Date <> @DateString,'Yes','')
,IsDateTime2Broken = IIF(DateTime2 <> @DateString,'Yes','')
FROM #Results
ORDER BY Alias,Conversion
;