Request a demo

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().

GoogleSQL for BigQuery · Checked against the official reference in November 2026

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

ArgumentDescription
timestamp_expressionThe 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;
Result
epoch_struncated
17953920001795392001

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;
Result
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;
Result
bucket_startevents
2026-11-23 10:00:00 UTC2
2026-11-23 10:15:00 UTC1

Common mistakes

  • Using EXTRACT(EPOCH FROM ts) (PostgreSQL), UNIX_TIMESTAMP(ts) (MySQL) or DATE_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.

Errors you may hit

More timestamp functions

All BigQuery timestamp functions · All functions · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.