DB/mssql
[mssql] convert yyyyMMddhhmmss string to datetime
건빵쥔광이씨
2017. 11. 23. 16:18
DECLARE @stringDatetime CHAR(14) = '20160823160000' -- yyyyMMddhhmmss DECLARE @convertedDatetime DATETIME = NULL SELECT @convertedDatetime = CAST((SUBSTRING(@stringDatetime,1,4) + '-' + SUBSTRING(@stringDatetime,5,2) + '-' + SUBSTRING(@stringDatetime,7,2) + ' ' + SUBSTRING(@stringDatetime,9,2) + ':' + SUBSTRING(@stringDatetime,11,2) + ':' + SUBSTRING(@stringDatetime,13,2)) AS DATETIME) SELECT @convertedDatetime AS convertedDatetime
참고 : [MSSQL] SUBSTRING 문자열 자르기
demo : http://rextester.com/TWLEM83934