UNIX_MILLIS
Overview
The UNIX_MILLIS()
function returns a given timestamp to a UNIX timestamp in milliseconds from 1970-01-01 00:00:00-00 (can be negative). Its syntax is illustrated below:
Its input type is a TIMESTAMP expression, and the return data type is int64
representing time in milliseconds.
Examples
#Case 1: Basic UNIX_MILLIS()
function
The below example uses the UNIX_MILLIS()
function to convert a given timestamp into a UNIX timestamp in milliseconds:
The final output will be as follows:
#Case 2: UNIX_MILLIS()
function using columns
Let’s suppose we have a table named time_example with the following timestamp values in the time_stamp column:
The above query will show the following table:
We want to convert all timestamp values into UNIX timestamp values in milliseconds. To do that, we have to run the following query:
The output displays all the timestamp entries of the table in the **time_stamp **column and the converted UNIX milliseconds timestamp entries in the column time_millis.