SQL DATETIMEOFFSET type
A 100 ns timestamp whose ±14:00 offset travels with the value, so comparisons happen in UTC space while display keeps the original offset.
- Category
- Dates & times
- Returns
datetimeoffset(n)- In this category
- 110 of 121
Syntax
CAST('2026-08-01 14:30:00 +02:00' AS DATETIMEOFFSET)
Engine support
| Engine | Support | Notes |
|---|---|---|
| SQL Server | Yes | Supported under this name. |
| PostgreSQL | Different name or syntax | timestamptz, instant-correct but discards the stored offset |
| MySQL | Not built in | no aware type |
| SQLite | Not built in | none |
| Oracle | Different name or syntax | TIMESTAMP WITH TIME ZONE: offsets and named zones |
Examples
SQL Server
SELECT CAST('2026-08-01 14:30:00 +02:00' AS DATETIMEOFFSET);
SQL Server
SELECT SYSDATETIMEOFFSET() AT TIME ZONE 'UTC'; -- renders in UTC, instant unchanged
PostgreSQL
SELECT '2026-08-01 14:30+02'::timestamptz; -- offset normalized on display
Good to know
- Comparisons normalize to UTC: '2026-08-01 14:30+02:00' equals '2026-08-01 12:30+00:00'; two rows can display differently and still be the same instant.
- The offset is not a zone: +02:00 says nothing about DST next month. Keep the IANA/Windows zone name in a second column if you need to reinterpret wall times later.
- Precision runs to 100 ns (default 7). Assigning a datetime or datetime2 attaches +00:00 whatever the server's zone, so CAST(GETDATE() AS datetimeoffset) labels local wall time as UTC. SYSDATETIMEOFFSET() carries the real offset.
Questions about DATETIMEOFFSET
datetimeoffset vs timestamptz?
Both compare as instants. datetimeoffset remembers the offset it was given; PostgreSQL's timestamptz re-renders in the session zone and forgets the original. Preserve-the-offset reporting favours datetimeoffset.
How do I strip the offset?
CAST(d AS datetime2) drops the offset without converting; use SWITCHOFFSET or AT TIME ZONE first if you need a specific zone's wall time.
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.