CURRENT_TIMESTAMP in milliseconds

后端 未结 19 950
失恋的感觉
失恋的感觉 2020-12-07 23:48

Is there any way to get milliseconds out of a timestamp in MySql or PostgreSql (or others just out of curiosity)?

SELECT CURRENT_TI         


        
19条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 00:20

    I faced the same issue recently and I created a small github project that contains a new mysql function UNIX_TIMESTAMP_MS() that returns the current timestamp in milliseconds.

    Also you can do the following :

    SELECT UNIX_TIMESTAMP_MS(NOW(3)) or SELECT UNIX_TIMESTAMP_MS(DateTimeField)

    The project is located here : https://github.com/silviucpp/unix_timestamp_ms

    To compile you need to Just run make compile in the project root.

    Then you need to only copy the shared library in the /usr/lib/mysql/plugin/ (or whatever the plugin folder is on your machine.)

    After this just open a mysql console and run :

    CREATE FUNCTION UNIX_TIMESTAMP_MS RETURNS INT SONAME 'unix_timestamp_ms.so';

    I hope this will help, Silviu

提交回复
热议问题