Skip to content

Instantly share code, notes, and snippets.

@friek
Created January 27, 2015 12:44
Show Gist options
  • Select an option

  • Save friek/21ad3fd11c176c77f105 to your computer and use it in GitHub Desktop.

Select an option

Save friek/21ad3fd11c176c77f105 to your computer and use it in GitHub Desktop.
MySQL to return the current timestamp + milliseconds
CREATE FUNCTION CURRENT_TIME_MILLIS ()
RETURNS BIGINT
LANGUAGE SQL
SQL SECURITY INVOKER
BEGIN
DECLARE _time BIGINT;
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 _time
from (select uuid() uid) as alias;
return _time;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment