TO_UNIX_TIMESTAMP_MS
Description
The TO_UNIX_TIMESTAMP_MS
function is used to convert various types of time expressions into a Unix timestamp (milliseconds). A Unix timestamp is the total number of milliseconds from 00:00:00 UTC on January 1, 1970, to the specified time. This function can handle multiple input formats, including strings, timestamps, etc.
Parameters
expr
: The input time expression, which can be a string, timestamp, etc.
Return Value
Returns a value of type bigint
, representing the Unix timestamp (milliseconds) after converting the input time expression.
Usage Example
- Convert from string to Unix timestamp (milliseconds):
In this example, the string '2022-02-01 10:23:32.123'
is converted to a Unix timestamp (milliseconds).
- Get the Unix timestamp (milliseconds) from the current time:
In this example, the NOW()
function is used to get the current time and convert it to a Unix timestamp (milliseconds).
- Convert from string to Unix timestamp (milliseconds), considering time zone differences:
- Convert from timestamp to Unix timestamp (milliseconds):
In this example, the timestamp TIMESTAMP "2022-02-01 10:23:32.123"
is converted to a Unix timestamp (milliseconds).
Notes
- The input time expression needs to conform to the supported format, otherwise, the conversion may fail.
- Time zone differences need to be considered during the conversion to ensure the accuracy of the result.
- Please ensure that the input parameters match the expected data types when using this function.