BigQuery · Timestamp function
BigQuery TIMESTAMP_SECONDS
TIMESTAMP_SECONDS(n) converts Unix epoch seconds (seconds since 1970-01-01 00:00:00 UTC) to a TIMESTAMP: TIMESTAMP_SECONDS(1795392000) is 2026-11-23 00:00:00 UTC. Wrap it in DATETIME(..., zone) for local time.
TIMESTAMP_SECONDS interprets an INT64 as seconds since the Unix epoch and returns the matching TIMESTAMP. It is the inverse of UNIX_SECONDS. Negative values are instants before 1970.
Check the unit before you convert. Epoch seconds for current dates have 10 digits; 13 digits are milliseconds (TIMESTAMP_MILLIS) and 16 digits are microseconds (TIMESTAMP_MICROS). Passing milliseconds here fails with "TIMESTAMP value is out of allowed range".
The argument must be INT64. Epoch values stored as FLOAT64 (for example 1795392000.5) or as STRING need a cast first; for fractional seconds, convert to microseconds: TIMESTAMP_MICROS(CAST(seconds * 1000000 AS INT64)).
Syntax
TIMESTAMP_SECONDS(int64_expression)Arguments and return value
| Argument | Description |
|---|---|
int64_expression | Seconds since 1970-01-01 00:00:00 UTC. NULL returns NULL. |
Returns: TIMESTAMP
Examples
Epoch seconds to TIMESTAMP and local DATETIME
SELECT
TIMESTAMP_SECONDS(1795392000) AS ts_utc,
DATETIME(TIMESTAMP_SECONDS(1795392000), 'America/New_York') AS new_york_local,
DATE(TIMESTAMP_SECONDS(1795392000), 'America/New_York') AS new_york_date;| ts_utc | new_york_local | new_york_date |
|---|---|---|
| 2026-11-23 00:00:00 UTC | 2026-11-22T19:00:00 | 2026-11-22 |
Decode an epoch column from an event feed
WITH events AS (
SELECT 'signup' AS event_name, 1795392000 AS epoch_s UNION ALL
SELECT 'purchase', 1795395723
)
SELECT event_name, TIMESTAMP_SECONDS(epoch_s) AS event_ts
FROM events
ORDER BY event_ts;| event_name | event_ts |
|---|---|
| signup | 2026-11-23 00:00:00 UTC |
| purchase | 2026-11-23 01:02:03 UTC |
String or float epochs need a cast
CAST(1795392000.75 AS INT64) would round to ...001. FLOOR keeps the second the event happened in.
WITH raw AS (
SELECT '1795392000' AS epoch_text, 1795392000.75 AS epoch_float
)
SELECT
TIMESTAMP_SECONDS(CAST(epoch_text AS INT64)) AS from_text,
TIMESTAMP_SECONDS(CAST(FLOOR(epoch_float) AS INT64)) AS from_float_floored
FROM raw;| from_text | from_float_floored |
|---|---|
| 2026-11-23 00:00:00 UTC | 2026-11-23 00:00:00 UTC |
Common mistakes
- Passing milliseconds.
TIMESTAMP_SECONDS(1795392000000)fails with "TIMESTAMP value is out of allowed range"; use TIMESTAMP_MILLIS. - Passing FLOAT64 or STRING. There is no matching signature; cast to INT64 first.
- Porting
TO_TIMESTAMP(epoch)(PostgreSQL, Snowflake) orFROM_UNIXTIME(epoch)(MySQL). In BigQuery use TIMESTAMP_SECONDS. - Reading the result as local time. The console shows UTC; use
DATETIME(TIMESTAMP_SECONDS(s), zone)for wall-clock time.
FAQ
How do I convert a Unix timestamp to a datetime in BigQuery?
DATETIME(TIMESTAMP_SECONDS(epoch_s), 'Europe/Berlin') for local wall-clock time, or TIMESTAMP_SECONDS(epoch_s) for a TIMESTAMP in UTC.
How do I know if an epoch value is seconds or milliseconds?
For dates in this century, seconds have 10 digits and milliseconds 13. Use TIMESTAMP_SECONDS for the first and TIMESTAMP_MILLIS for the second.
What is the opposite of TIMESTAMP_SECONDS?
UNIX_SECONDS(ts) returns the epoch seconds of a TIMESTAMP.
Related
Errors you may hit
More timestamp functions
All BigQuery timestamp functions · All functions · BigQuery error messages
