Request a demo

BigQuery · Datetime function

BigQuery DATETIME

DATETIME builds a DATETIME from numbers, from a DATE and TIME, or converts a TIMESTAMP to local wall-clock time: DATETIME(ts, 'Europe/Berlin'). It is the usual way to convert a UTC timestamp to a local time zone in BigQuery.

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

DATETIME is a civil date and time, what a calendar and a wall clock show, without a time zone. The DATETIME function creates one in three ways: from six integers (DATETIME(2026, 11, 23, 18, 45, 0)), from a DATE plus an optional TIME, or from a TIMESTAMP read in a time zone.

The TIMESTAMP form is how you convert time zones. A TIMESTAMP is one instant; DATETIME(ts, 'Asia/Kolkata') tells you what clocks in Kolkata showed at that instant, applying DST rules for zones that have them. Without the second argument the zone is UTC. The reverse conversion, local wall time back to an instant, is TIMESTAMP(datetime_value, 'Asia/Kolkata').

DATETIME vs TIMESTAMP: use TIMESTAMP for when something happened (logs, events, loads), and DATETIME for local business times that should not move when someone views them from another zone, such as a store's opening hours or a scheduled local delivery slot. Comparing or joining the two types needs an explicit conversion.

Syntax

DATETIME(year, month, day, hour, minute, second)

DATETIME(date_expression[, time_expression])

DATETIME(timestamp_expression[, time_zone])

Arguments and return value

ArgumentDescription
year, month, day, hour, minute, secondINT64 values for each part.
date_expressionA DATE. Without time_expression the time is midnight.
time_expressionOptional TIME of day to combine with the DATE.
timestamp_expressionA TIMESTAMP to express as local wall-clock time.
time_zoneOptional STRING zone name or offset for the TIMESTAMP form. Defaults to UTC.

Returns: DATETIME

Examples

Build a DATETIME

SELECT
  DATETIME(2026, 11, 23, 18, 45, 0) AS from_parts,
  DATETIME(DATE '2026-11-23', TIME '18:45:00') AS from_date_and_time,
  DATETIME(DATE '2026-11-23') AS midnight;
Result
from_partsfrom_date_and_timemidnight
2026-11-23T18:45:002026-11-23T18:45:002026-11-23T00:00:00

Convert a UTC timestamp to local times

Kolkata is UTC+05:30, so it is already 00:15 on the next day.

SELECT
  DATETIME(TIMESTAMP '2026-11-23 18:45:00+00', 'Europe/Berlin') AS berlin,
  DATETIME(TIMESTAMP '2026-11-23 18:45:00+00', 'Asia/Kolkata') AS kolkata,
  DATETIME(TIMESTAMP '2026-11-23 18:45:00+00', 'America/Los_Angeles') AS los_angeles;
Result
berlinkolkatalos_angeles
2026-11-23T19:45:002026-11-24T00:15:002026-11-23T10:45:00

Daylight saving time is applied for the date

Berlin is UTC+2 in summer and UTC+1 in winter. A fixed offset such as '+01' would get the summer value wrong.

SELECT
  DATETIME(TIMESTAMP '2026-07-01 12:00:00+00', 'Europe/Berlin') AS summer,
  DATETIME(TIMESTAMP '2026-11-23 12:00:00+00', 'Europe/Berlin') AS winter;
Result
summerwinter
2026-07-01T14:00:002026-11-23T13:00:00

Local wall time back to a UTC timestamp

SELECT TIMESTAMP(DATETIME '2026-11-23 09:00:00', 'Europe/Berlin') AS opens_at_utc;
Result
opens_at_utc
2026-11-23 08:00:00 UTC

Common mistakes

  • Treating a DATETIME as UTC or as local without knowing which. The value carries no zone; document the zone in the column name (created_local_berlin) or store a TIMESTAMP.
  • Using a fixed offset for a zone with DST. DATETIME(ts, '+01') is wrong for Berlin from late March to late October; use 'Europe/Berlin'.
  • Porting CONVERT_TZ (MySQL), CONVERT_TIMEZONE (Snowflake, Redshift) or AT TIME ZONE on a column (PostgreSQL, SQL Server). In BigQuery, DATETIME(ts, zone) converts an instant to local time and TIMESTAMP(dt, zone) converts local time to an instant.
  • Comparing DATETIME with TIMESTAMP. datetime_col > CURRENT_TIMESTAMP() fails with No matching signature for operator; convert one side explicitly.

FAQ

How do I convert a timezone in BigQuery?

Use DATETIME(ts, 'Europe/Berlin') to see a UTC TIMESTAMP as Berlin wall-clock time, and TIMESTAMP(dt, 'Europe/Berlin') to turn a Berlin wall-clock DATETIME into a TIMESTAMP. FORMAT_TIMESTAMP with a zone returns a local STRING.

What is the difference between DATETIME and TIMESTAMP in BigQuery?

TIMESTAMP is an absolute instant with microsecond precision, shown in UTC. DATETIME is a calendar date and clock time with no zone, so the same DATETIME means different instants in different places.

How do I convert a Unix timestamp to a datetime?

DATETIME(TIMESTAMP_SECONDS(epoch_seconds), 'America/New_York'), or TIMESTAMP_MILLIS for milliseconds. Leave out the zone for UTC.

Errors you may hit

More datetime functions

All BigQuery datetime 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.