0

Having date in 1/26/2016 14:54 format and need it in 20160126 format in MSSQL. I am using REPLACE(CONVERT(DATE, DATE_OF_AQUISITION,112),'-','')

but it is giving error

"Msg 9807, Level 16, State 0, Line 47 The input character string does not follow style 112, either change the input character string or use a different style."

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Mohit Vijay
  • 39
  • 1
  • 10

3 Answers3

0

Convert to date before replace.

SELECT REPLACE(CONVERT(CHAR(10),CONVERT(DATE,DATE_OF_AQUISITION), 112),'/','')
Munavvar
  • 802
  • 1
  • 11
  • 33
0

Simple Example But I'm not sure

Just remove 112 conversion you have added

declare @dt VARCHAR(20) = '1/26/2016 14:54'

select REPLACE(CONVERT(DATE,@dt),'-','')
mohan111
  • 8,633
  • 4
  • 28
  • 55
0

This is example which show a result that you want.

Hope this is also help for you.

select Convert(varchar,TaskDate,112) TaskDate from XYZ.

Result-20161121