# parseSqlOffsetDateTime

Industry: Core

## Signature

```ts
parseSqlOffsetDateTime(value: string): string
```

Parse 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>`, as `sqlOffsetDateTime` matches: a single space separator, a four-digit year `0001`–`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:MM` or `±HH:MM:SS` (PostgreSQL's hour-only and seconds forms), with one optional space before it (SQL Server and Oracle). Offset hours `00`–`23` are 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 with `toOffsetInstant(…)?.instant`.
- PostgreSQL's offset is the session `TimeZone`'s rendering, not stored data. SQL Server's is stored.
- **Normalised:**
- A `T` separator.
- An hour-only offset gains `:00`.
- Offset seconds of `00` are 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:**
- `T` and `Z` (ISO 8601: `toOffsetInstant`, `parseRfc3339`). One form has both readers: a space, then a full `±HH:MM` with no space before it. `parseRfc3339` returns it zoned (`…+05:30[+05:30]`); this one returns it with the offset alone;
- text with no offset (`parseSqlDateTime`);
- a `BC` year or `infinity` (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

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | SQL timestamp-with-time-zone text, e.g. `"2024-03-15 14:30:00+00"` |

## Returns

ISO 8601 date-time with offset, or `""` on invalid input

## Examples

```ts
import { parseSqlOffsetDateTime } from "@northguild/gmt/instant/parse";

parseSqlOffsetDateTime("2024-03-15 14:30:00+00") // "2024-03-15T14:30:00+00:00"
```

## Source

[instant/parse/parseSqlOffsetDateTime.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/instant/parse/parseSqlOffsetDateTime.ts)
