SQL AT TIME ZONE function
Tags a naive timestamp with a zone or renders an aware timestamp in a zone: the same clause, meaning opposite things depending on the input type.
- Категория
- Dates & times
- Returns
timestamptz / timestamp (PG); datetimeoffset / datetime (SS)- In this category
- 105 of 121
Синтаксис
ts AT TIME ZONE 'zone'
Поддержка движка
| Движок | Support | Заметки |
|---|---|---|
| SQL Server | Да | Supported under this name. |
| PostgreSQL | Да | native: timestamptz and timestamp both |
| MySQL | Different name or syntax | CONVERT_TZ(dt, from_zone, to_zone) |
| SQLite | Not built in | no zone support beyond localtime/utc modifiers |
| Oracle | Да | ts AT TIME ZONE 'zone' on TIMESTAMP types; FROM_TZ to tag a naive value |
Примеры
PostgreSQL
SELECT TIMESTAMP '2026-08-01 14:30' AT TIME ZONE 'Europe/Paris';
SQL Server
SELECT CAST('2026-08-01 14:30' AS datetime2) AT TIME ZONE 'Central European Standard Time'; -- 2026-08-01 14:30:00 +02:00
Oracle
SELECT SYSTIMESTAMP AT TIME ZONE 'Europe/Paris' FROM dual;
Полезно знать
- Direction depends on input type: on PostgreSQL, timestamp AT TIME ZONE 'Europe/Paris' produces a timestamptz (interprets), while timestamptz AT TIME ZONE 'Europe/Paris' produces a timestamp (renders). Applying it twice flips the type back.
- SQL Server (2016+) uses Windows zone names ('Central European Standard Time'), PostgreSQL and Oracle use IANA names ('Europe/Paris'); one mapping table does not serve both.
- Wall times inside a DST gap move forward: 2026-03-08 02:30 in America/New_York ('Eastern Standard Time' on SQL Server) comes back as 03:30 -04:00 on both PostgreSQL and SQL Server, so a round-trip changes the value.
Questions about AT TIME ZONE
Why does AT TIME ZONE sometimes add and sometimes drop the zone?
Input type decides: naive in means 'interpret this wall time in the zone' (adds awareness); aware in means 'show me this instant as the zone's wall time' (drops awareness).
Do the two engines accept the same zone names?
No. PostgreSQL wants IANA identifiers; SQL Server wants Windows time zone registry names. Store the right kind per engine.
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, MySQL, 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.