Posts

Showing posts with the label sql-server-2016

How to convert 17 digit number to yyyy-mm-dd hh:mi:ss:mmm format in SQL Server 2016?

How to convert 17 digit number to yyyy-mm-dd hh:mi:ss:mmm format in SQL Server 2016? How to convert 17 digit number to yyyy-mm-dd hh:mi:ss:mmm format in SQL Server 2016? yyyy-mm-dd hh:mi:ss:mmm For example from 20170201140517844 to 2017-02-01 14:05:17:844 I tried this: select CONVERT(datetime, CAST(20170201140517844 AS char(30)), 126) select CONVERT(datetime, CAST(20170201140517844 AS char(30)), 121) but I'm getting an error Msg 241, Level 16, State 1, Line 6 Conversion failed when converting date and/or time from character string. okay just found a way to do this like below using STUFF function SELECT CONVERT(DATETIME, STUFF(STUFF(STUFF(STUFF(20170201140517844,15,0,'.'),13,0,':'),11,0,':'),9,0,' ')) AS FormattedDate – Saini Jul 2 at 2:34 ...