I have a legacy database. This database has stored the data in the format '02/10/2015 14:26:48'
.
I am trying to convert this date&time to apply sorting to fulfill my requirements:
DECLARE @date nvarchar(50) = N'02/10/2015 14:26:48'
SELECT CONVERT(datetime, LEFT(@date, 19), 126)
But I am getting the following error:
SQL Error [241] [S0001]: An error occurred during the current command (Done status 0). Conversion failed when converting date and/or time from character string.
15
One way would be to pull out the invividual parts of the date part and reorder them to utc? Swap day and month around to required format
DECLARE @date nvarchar(50) = N'02/10/2015 14:26:48'
SELECT CONVERT(datetime, SUBSTRING(@date, 7, 4) + '-' + SUBSTRING(@date, 4, 2) + '-' + SUBSTRING(@date, 1, 2) + ' ' + SUBSTRING(@date, 12, 8))
4