I think the problem is the value 28/12/2018 20:52 which is the format dd/mm/yyyy. So you need to
- split the datetime string into the date and time string,
- convert the date string to the date format YYYY-MM-DD
- convert it back to the string
- append the time string
- convert the datetime string to datetime
See the following example:
DECLARE @d1 varchar(20);
DECLARE @d2 varchar(20);
SET @d1 = '28/12/2018 20:52';
SET @d2 = '10-Mar-19 11:15:00';
SELECT
LEFT(@d1, CHARINDEX(' ', @d1)) AS d1_Date_String,
SUBSTRING(@d1, CHARINDEX(' ', @d1) + 1, LEN(@d1) - CHARINDEX(' ', @d1)) AS d1_Time_String,
LEFT(@d2, CHARINDEX(' ', @d2)) AS d2_Date_String,
SUBSTRING(@d2, CHARINDEX(' ', @d2) + 1, LEN(@d2) - CHARINDEX(' ', @d2)) AS d2_Time_String,
CONVERT(datetime, CAST(CONVERT(date, LEFT(@d1, CHARINDEX(' ', @d1)), 105) AS varchar(10)) + ' ' + SUBSTRING(@d1, CHARINDEX(' ', @d1) + 1, LEN(@d1) - CHARINDEX(' ', @d1)), 121) AS d1_Datetime,
CONVERT(datetime, CAST(CONVERT(date, LEFT(@d2, CHARINDEX(' ', @d2)), 105) AS varchar(10)) + ' ' + SUBSTRING(@d2, CHARINDEX(' ', @d2) + 1, LEN(@d2) - CHARINDEX(' ', @d2)), 121) AS d2_Datetime;
So you can use the following code to convert the datetime string to the datetime format yyyy-mm-dd hh:mm:ss:
CONVERT(datetime, CAST(CONVERT(date, LEFT([DATE_STRING_COLUMN], CHARINDEX(' ', [DATE_STRING_COLUMN])), 105) AS varchar(10)) + ' ' + SUBSTRING([DATE_STRING_COLUMN], CHARINDEX(' ', [DATE_STRING_COLUMN]) + 1, LEN([DATE_STRING_COLUMN]) - CHARINDEX(' ', [DATE_STRING_COLUMN])), 121)