Skip to content

Instantly share code, notes, and snippets.

@markmo
Created March 11, 2013 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markmo/5138724 to your computer and use it in GitHub Desktop.
Save markmo/5138724 to your computer and use it in GitHub Desktop.
Convert integer key to datetime
SELECT CONVERT(DATETIME, CONVERT(VARCHAR, DateKey) + ' ' +
SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR, DateKey), 6), 1, 2) + ':' +
SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR, TimeKey), 6), 3, 2) + ':' +
SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR, TimeKey), 6), 5, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment