-2

I have a database field Column_A which is in Varchar(16) not null and the values are for example 20191210215033CS but I want to break it like 2019-12-10 21:50:33

Since it is a production database there is no way to change the data type.

Tried the below code

SELECT convert(datetime, 'Column_A', 120) but getting the error 

Conversion failed when converting date and/or time from character string.

Is their any workaround ? Any help will be greatly appreciated !

2
  • SELECT convert(datetime, Column_A, 120) – Erik Darling Oct 27 '20 at 19:12
  • Conversion failed when converting date and/or time from character string.Get this error – SQL_NoExpert Oct 27 '20 at 19:40
1

'Column_A' is not a date, Column_A may be.

Select convert(datetime,format(convert(bigint,left(Column_A,14)),
                               '####/##/## ##:##:##'))

Db fiddle

This ignores the 'CS' from your example. A kind of timezone?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.