The conversion of a varchar data type to a datetime data type resulted in an out-of-range value (Konwersja typu danych varchar na typ danych datetime spowodowała utworzenie wartości leżącej poza zakresem)

This error can be result of wrong `dateformat` setting on database. Example below.

ERROR – `dmy` dateformat:
SET DATEFORMAT dmy;
DECLARE @datetime datetime = '2021-12-31';  
SELECT CASE WHEN @datetime >= '2021-11-22' THEN 1 ELSE 0 END;
OK – `mdy` dateformat:
SET DATEFORMAT mdy;
DECLARE @datetime datetime = '2021-12-31';  
SELECT CASE WHEN @datetime >= '2021-11-22' THEN 1 ELSE 0 END;
Utils:
DBCC useroptions;
Default dateformat is connected with `DEFAULT_LANGUAGE` set on account.