How to retrieve microseconds or milliseconds from MySQL current time?

前端 未结 5 2141
天涯浪人
天涯浪人 2021-01-02 02:17

I am trying to create my first stored function on MySQL. In this function I want to return the timestamp of the current date and time with 3 microsecond digits like this:

5条回答
  •  情话喂你
    2021-01-02 02:32

    Also you can

    mysql> select now(3) as millisecond, now(6) as microsecond, round(1000 * unix_timestamp(now(3))) elapsed_millisecond, round(unix_timestamp() * 1000  + MICROSECOND(now(6)) / 1000) elapsed_microsecond;
    +-------------------------+----------------------------+---------------------+---------------------+
    | millisecond             | microsecond                | elapsed_millisecond | elapsed_microsecond |
    +-------------------------+----------------------------+---------------------+---------------------+
    | 2019-12-10 11:49:43.568 | 2019-12-10 11:49:43.568767 |       1575949783568 |       1575949783569 |
    +-------------------------+----------------------------+---------------------+---------------------+
    1 row in set (0.01 sec)
    

提交回复
热议问题