Hi to all,
i have a strange behaviuor converting a column to time.
I have an nvarchar column with a date in this format: dd/MM/yyyy hh:mm:ss and i'm trying to convert it to type TIME but i have an error on conversion.
My query is
select top 1
''''+right(MESSAGE_DATE,8)+'''',
''''+LTRIM(RTRIM(SUBSTRING(MESSAGE_DATE,12, 9)))+':000'+'''',
--CONVERT(DATETIME,right(MESSAGE_DATE,8),8) ,
--CONVERT(TIME,LTRIM(RTRIM(SUBSTRING(MESSAGE_DATE,12, 9)))+':000',114),
--CONVERT(TIME,CAST(right(MESSAGE_DATE,8) as NVARCHAR(8)),8)
FROM TABLE
I use the right() and substring() func to get the portion of string with time, but every style conversion i tried it give to me the same error:
The input character string does not follow style 114, either change the input character string or use a different style.
i tried to do this test: SELECT CONVERT(TIME,'23:52:25:000',114),CONVERT(DATETIME,'23:52:25:000',114) and i was able to get the correct time without errors.
Can anyone help me to solve this issue?
Best Regards
Sergio
