This article will assist you in how to use the TIMESTAMP_MILLIS() function to convert a given UNIX timestamp in milliseconds to a timestamp.
The TIMESTAMP_MILLIS() function converts a given UNIX timestamp value in milliseconds since 1970-01-01 00:00:00 UTC into a timestamp. Its syntax can be seen below:
Its input type is an int64 expression which represents a UNIX timestamp in milliseconds and the return data type is a timestamp.
#Case 1: Basic TIMESTAMP_MILLIS() function
The below example uses the TIMESTAMP_MILLIS() function to convert a given UNIX timestamp in milliseconds into a timestamp without a timezone.
The final output will be as follows:
#Case 2: TIMESTAMP_MILLIS() function using columns
Let’s suppose we have a table named unix_example with the following UNIX time values in milliseconds in the unix_timestamp column:
The above query will show the following table:
We want to convert all UNIX timestamp values in milliseconds to timestamp values. To do that, we have to run the following query:
The output displays all the entries in the table in UNIX timestamp format (in milliseconds) in the unix_timestamp column and in the timestamp format in the column timestamp_value without timezone.