TIMESTAMP_SECONDS
This article will assist you in how to use the TIMESTAMP_SECONDS() function to convert a given UNIX timestamp in seconds to a timestamp.
Overview
The TIMESTAMP_SECONDS() function converts a given UNIX timestamp value in seconds from 1970-01-01 00:00:00 UTC into a timestamp. Its syntax can be seen below:
Its input type is an int64 expression representing a UNIX timestamp in seconds, and the return data type is a timestamp.
Examples
#Case 1: Basic TIMESTAMP_SECONDS() function
The below example uses the TIMESTAMP_SECONDS() function to convert a given UNIX timestamp in seconds into a timestamp:
The final output will be as follows:
#Case 2: TIMESTAMP_SECONDS() function using columns
Let’s suppose we have a table named unix_time with the following UNIX time values in seconds:
The above query will show the following table:
We want to convert all UNIX timestamp values in seconds 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 seconds) in the unix_time column and in the timestamp format without timezone in the column timestamp_value.
