BigQuery · Timestamp function
BigQuery UNIX_SECONDS
UNIX_SECONDS(ts) returns the number of seconds since 1970-01-01 00:00:00 UTC as INT64, dropping fractions of a second. It is BigQuery's answer to EXTRACT(EPOCH FROM ts) and UNIX_TIMESTAMP().
UNIX_SECONDS converts a TIMESTAMP to Unix epoch seconds. Sub-second precision is truncated by rounding down to the start of the second. The inverse is TIMESTAMP_SECONDS.
Epoch seconds are useful for exporting to systems that expect integers, for arithmetic such as fixed-width buckets (DIV(UNIX_SECONDS(ts), 900) for 15-minute slots), and for durations between instants. A TIMESTAMP has no zone, so the result is the same whatever zone you think of the time in; to get the epoch of a local wall-clock time, convert it first with TIMESTAMP(datetime_value, zone).
UNIX_SECONDS only takes a TIMESTAMP. For a DATE use UNIX_DATE (days) or UNIX_SECONDS(TIMESTAMP(d)) for midnight UTC.
Syntax
UNIX_SECONDS(timestamp_expression)Arguments and return value
| Argument | Description |
|---|---|
timestamp_expression | The TIMESTAMP to convert. NULL returns NULL. |
Returns: INT64
Examples
Epoch seconds, with fractions dropped
SELECT
UNIX_SECONDS(TIMESTAMP '2026-11-23 00:00:00+00') AS epoch_s,
UNIX_SECONDS(TIMESTAMP '2026-11-23 00:00:01.999+00') AS truncated;| epoch_s | truncated |
|---|---|
| 1795392000 | 1795392001 |
Epoch of a local wall-clock time
09:00 in Berlin is 08:00 UTC, 8 hours after midnight UTC (1795392000 + 28800).
SELECT UNIX_SECONDS(TIMESTAMP(DATETIME '2026-11-23 09:00:00', 'Europe/Berlin')) AS berlin_9am;| berlin_9am |
|---|
| 1795420800 |
15-minute buckets
WITH events AS (
SELECT TIMESTAMP '2026-11-23 10:03:00+00' AS event_ts UNION ALL
SELECT TIMESTAMP '2026-11-23 10:14:59+00' UNION ALL
SELECT TIMESTAMP '2026-11-23 10:15:00+00'
)
SELECT
TIMESTAMP_SECONDS(DIV(UNIX_SECONDS(event_ts), 900) * 900) AS bucket_start,
COUNT(*) AS events
FROM events
GROUP BY bucket_start
ORDER BY bucket_start;| bucket_start | events |
|---|---|
| 2026-11-23 10:00:00 UTC | 2 |
| 2026-11-23 10:15:00 UTC | 1 |
Common mistakes
- Using
EXTRACT(EPOCH FROM ts)(PostgreSQL),UNIX_TIMESTAMP(ts)(MySQL) orDATE_PART(epoch_second, ts)(Snowflake). In BigQuery use UNIX_SECONDS. - Passing a DATETIME. There is no matching signature; convert with
TIMESTAMP(dt, zone)and choose the zone deliberately. - Expecting rounding. 00:00:01.999 becomes 1 second past the minute, not 2.
FAQ
How do I convert a timestamp to a Unix timestamp in BigQuery?
UNIX_SECONDS(ts) for seconds, UNIX_MILLIS(ts) for milliseconds, UNIX_MICROS(ts) for microseconds.
Does UNIX_SECONDS depend on the time zone?
No. A TIMESTAMP is an absolute instant, so its epoch value is the same everywhere. Zones only matter when you build the TIMESTAMP from a local time.
Related
Errors you may hit
More timestamp functions
All BigQuery timestamp functions · All functions · BigQuery error messages
