This query is to convert the DateTimeOffset
into the format yyyyMMddhhss
with Offset. I have replaced the hyphens, colon(:), period(.)
from the data, and kept the hyphen for the seperation of Offset from the DateTime
.
SELECT REPLACE(SUBSTRING(CONVERT(VARCHAR(33),SYSDATETIMEOFFSET(),126), 1, 8), '-', '') +
SUBSTRING(REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(33), SYSDATETIMEOFFSET(), 126),'T',''),'.',''),':',''),9,DATALENGTH(CONVERT(VARCHAR(33), SYSDATETIMEOFFSET(), 126)))