Skip to content

Instantly share code, notes, and snippets.

@romuald
Created July 9, 2020 13:20
Show Gist options
  • Save romuald/291dadf2840bad3bbee44688d9e8bfaf to your computer and use it in GitHub Desktop.
Save romuald/291dadf2840bad3bbee44688d9e8bfaf to your computer and use it in GitHub Desktop.
Converts a UUID1 variable to a timestamp
SET @uuid='31ae75f0-cbe0-11e8-a147-bc5ff4690f6a';
SELECT
IF(SUBSTRING(@uuid, 15, 1) = '1',
'1582-10-15' + INTERVAL (
CONV(CONCAT(SUBSTRING(@uuid, 16, 3), SUBSTRING(@uuid, 10, 4), SUBSTRING(@uuid, 1, 8)),
16, 10)
/ 10000000) SECOND,
NULL) AS uuid_as_timestamp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment