parseSqlOffsetDateTime
Signature
Section titled “Signature”parseSqlOffsetDateTime(value: string): stringParse SQL TIMESTAMP WITH TIME ZONE text into an ISO 8601 date-time string that keeps the offset: SQL-92’s YYYY-MM-DD HH:MM:SS±HH:MM, and the variants PostgreSQL timestamptz, SQL Server datetimeoffset and Oracle under an ISO NLS_TIMESTAMP_TZ_FORMAT print.
- Grammar: SQL-92 §5.3
<timestamp string>and<time zone interval>, assqlOffsetDateTimematches: a single space separator, a four-digit year0001–9999, two-digit month, day, hour, minute and second (seconds are required), an optional.followed by up to 9 fraction digits, then an offset±HH,±HH:MMor±HH:MM:SS(PostgreSQL’s hour-only and seconds forms), with one optional space before it (SQL Server and Oracle). Offset hours00–23are GMT’s rule, wider than SQL-92 (§5.3 Syntax Rule 25: −12:59 … +13:00), so that+14:00(SQL Server, MySQL, Oracle) is read; 24 and above is outside Temporal’s offset grammar. - The offset is kept, not applied. The result is the same wall time and offset in ISO form.
- Read the instant and offset with
toOffsetInstant, or the UTC instant withtoOffsetInstant(…)?.instant. - PostgreSQL’s offset is the session
TimeZone’s rendering, not stored data. SQL Server’s is stored. - Normalised:
- A
Tseparator. - An hour-only offset gains
:00. - Offset seconds of
00are dropped. - A negative zero offset is written
+00:00. - The fraction is written as Temporal writes one: trailing zeros dropped, and a bare
.is dropped. - Not read here, with the right reader for each:
TandZ(ISO 8601:toOffsetInstant,parseRfc3339). One form has both readers: a space, then a full±HH:MMwith no space before it.parseRfc3339returns it zoned (…+05:30[+05:30]); this one returns it with the offset alone;- text with no offset (
parseSqlDateTime); - a
BCyear orinfinity(no Temporal value); - a leap second (
:60), which SQL-92 §6.1 Table 10 allows; Temporal has no leap seconds. - Precision: up to 9 fraction digits. PostgreSQL prints 6, SQL Server 7, and Oracle up to 9.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | SQL timestamp-with-time-zone text, e.g. "2024-03-15 14:30:00+00" |
Returns
Section titled “Returns”ISO 8601 date-time with offset, or "" on invalid input
Examples
Section titled “Examples”import { parseSqlOffsetDateTime } from "@northguild/gmt/instant/parse";
parseSqlOffsetDateTime("2024-03-15 14:30:00+00") // "2024-03-15T14:30:00+00:00"Source
Section titled “Source”© 2026 NorthGuild · Licences
Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.