Skip to content

Instantly share code, notes, and snippets.

@DimuDesigns
Last active December 17, 2016 18:47
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 DimuDesigns/6a27fbe27b1b400b6de1f85d23e02548 to your computer and use it in GitHub Desktop.
Save DimuDesigns/6a27fbe27b1b400b6de1f85d23e02548 to your computer and use it in GitHub Desktop.
MySQL Stored Function to generate Unix timestamp in milliseconds (UTC/GMT)
DROP FUNCTION IF EXISTS `getUnixTimestampInMilliseconds`;
CREATE FUNCTION `getUnixTimestampInMilliseconds`()
RETURNS bigint(20)
BEGIN
DECLARE milliseconds BIGINT DEFAULT 0;
SELECT CONV(
CONCAT(
SUBSTRING(uid,16,3),
SUBSTRING(uid,10,4),
SUBSTRING(uid,1,8)),
16,10)
DIV 10000
- (141427 * 24 * 60 * 60 * 1000) INTO milliseconds
FROM (SELECT UUID() uid) AS alias;
RETURN milliseconds;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment