Request a demo

BigQuery · Timestamp function

BigQuery TIMESTAMP_MILLIS

TIMESTAMP_MILLIS(n) converts milliseconds since 1970-01-01 00:00:00 UTC to a TIMESTAMP. Use it for 13-digit epoch values from JavaScript Date.now(), Kafka, Java and most event trackers.

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

TIMESTAMP_MILLIS reads an INT64 as milliseconds since the Unix epoch and returns the matching TIMESTAMP, keeping the millisecond part. The inverse is UNIX_MILLIS.

Millisecond epochs are the default in JavaScript (Date.now()), Java (System.currentTimeMillis()) and Kafka record timestamps; current values have 13 digits. Ten-digit values are seconds (TIMESTAMP_SECONDS), and passing them here produces dates in January 1970 instead of an error, which is easy to miss.

The argument must be INT64; cast STRING or FLOAT64 values first. For 16-digit microsecond values use TIMESTAMP_MICROS.

Syntax

TIMESTAMP_MILLIS(int64_expression)

Arguments and return value

ArgumentDescription
int64_expressionMilliseconds since 1970-01-01 00:00:00 UTC. NULL returns NULL.

Returns: TIMESTAMP

Examples

Milliseconds to TIMESTAMP

SELECT
  TIMESTAMP_MILLIS(1795392000000) AS ts,
  FORMAT_TIMESTAMP('%F %H:%M:%E3S', TIMESTAMP_MILLIS(1795395723456)) AS with_millis;
Result
tswith_millis
2026-11-23 00:00:00 UTC2026-11-23 01:02:03.456

Seconds passed by mistake land in 1970

1,795,392,000 milliseconds is about 20.8 days after the epoch. No error is raised.

SELECT TIMESTAMP_MILLIS(1795392000) AS wrong_unit;
Result
wrong_unit
1970-01-21 18:43:12 UTC

A feed that mixes seconds and milliseconds

Values of 100,000,000,000 and above are treated as milliseconds. As seconds, that threshold would be the year 5138.

WITH raw AS (
  SELECT 'a' AS event_id, 1795392000 AS epoch_value UNION ALL
  SELECT 'b', 1795392000000
)
SELECT
  event_id,
  IF(epoch_value >= 100000000000, TIMESTAMP_MILLIS(epoch_value), TIMESTAMP_SECONDS(epoch_value)) AS event_ts
FROM raw
ORDER BY event_id;
Result
event_idevent_ts
a2026-11-23 00:00:00 UTC
b2026-11-23 00:00:00 UTC

Common mistakes

  • Passing seconds. TIMESTAMP_MILLIS(1795392000) silently returns a time in January 1970; check MIN and MAX of the result after a conversion.
  • Passing a STRING or FLOAT64 column. Cast to INT64 first: TIMESTAMP_MILLIS(CAST(ts_ms AS INT64)).
  • Porting TO_TIMESTAMP(ms / 1000) from PostgreSQL. In BigQuery, dividing gives FLOAT64, which TIMESTAMP_SECONDS rejects; TIMESTAMP_MILLIS takes the integer directly.

FAQ

How do I convert epoch milliseconds to a timestamp in BigQuery?

TIMESTAMP_MILLIS(ms). For local wall-clock time, wrap it: DATETIME(TIMESTAMP_MILLIS(ms), 'America/Chicago').

How do I convert a timestamp back to milliseconds?

UNIX_MILLIS(ts). It truncates any microseconds.

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.