Last active
December 17, 2016 18:47
-
-
Save DimuDesigns/6a27fbe27b1b400b6de1f85d23e02548 to your computer and use it in GitHub Desktop.
MySQL Stored Function to generate Unix timestamp in milliseconds (UTC/GMT)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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