SQL TIMESTAMP WITH TIME ZONE type
A timestamp paired with a zone or offset, stored as one instant in time and displayed in whatever zone the session or query asks for.
- カテゴリ
- Dates & times
- Returns
timestamp with time zone- In this category
- 108 of 121
構文
TIMESTAMPTZ '2026-08-01 14:30+02'
エンジンサポート
| エンジン | Support | メモ |
|---|---|---|
| SQL Server | Different name or syntax | datetimeoffset is the offset-carrying type |
| PostgreSQL | はい | timestamptz, the type to default to |
| MySQL | Not built in | no aware type; naive DATETIME only |
| SQLite | Not built in | none; text storage conventions only |
| Oracle | はい | TIMESTAMP WITH TIME ZONE, the original |
例
PostgreSQL
SELECT TIMESTAMPTZ '2026-08-01 14:30+02' AT TIME ZONE 'UTC'; -- 12:30
Oracle
SELECT CAST(TIMESTAMP '2026-08-01 14:30:00' AS TIMESTAMP WITH TIME ZONE) FROM dual;
PostgreSQL
CREATE TABLE events (starts_at timestamptz NOT NULL);
知っておくと便利なこと
- Neither engine stores the literal string you typed: PostgreSQL normalizes to UTC (the display offset moves with the session), Oracle keeps the stored offset in the column but converts for comparisons.
- It is a point in time, not a schedule: '09:00 in the shop's zone' belongs in a naive timestamp plus a zone column, because timestamptz pins the instant and DST will shift future occurrences.
- Comparisons and indexes work in UTC space, so rows inserted from Tokyo and London sort correctly: the whole reason to prefer timestamptz over naive timestamps for events.
Questions about TIMESTAMP WITH TIME ZONE
Should I always use timestamptz in PostgreSQL?
For instants, yes. Use timestamp without zone only for zone-independent wall times (schedules, opening hours), and pair those with a zone column when users span zones.
What does SQL Server offer instead?
datetimeoffset(n) carries the offset with the value; AT TIME ZONE builds and renders it. It is the closest cousin to Oracle's type.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.