Converting Datatime value in YYYYMMDDHHMMSS format is not that complex as it sounds :)
SELECT CONVERT(VARCHAR(10),GETDATE(),112) --Date alone
SELECT CONVERT(VARCHAR(10),GETDATE(),108) - Time alone
The only problem is in the Time portion we would get ":" separator within HH:MM:SS. So we need to just replace colon with space and concatenate both this result to get an output in the expected format.
Solution:
SELECT
CONVERT(VARCHAR(10),GETDATE(),112) +
REPLACE(CONVERT(VARCHAR(10),GETDATE(),108),':','')
AS [YYYYMMDDHHMMSS]
Comments
How can you do the opposite?
Thx