# formatSqlDateTime

Industry: Core

## Signature

```ts
formatSqlDateTime(value: string): string
```

Format a plain ISO 8601 datetime string as a SQL timestamp literal without a time zone — the `YYYY-MM-DD HH:MM:SS[.fff]` form of standard SQL `TIMESTAMP` and MySQL/SQLite `DATETIME` columns.

- **Grammar:** SQL-92 §5.3 `<timestamp string>` and the ODBC `ts` escape, which `parseSqlDateTime` reads: the date, a single space, and the time with seconds always written.
- A year outside SQL-92's `0001`–`9999` (Table 10) returns `""`: the literal has no sign and no expanded year to write it with.
- **Plain only.** SQL's offset-carrying `TIMESTAMP WITH TIME ZONE` literal (`YYYY-MM-DD HH:MM:SS±HH:MM`, e.g. PostgreSQL) is read by `parseSqlOffsetDateTime` (`@northguild/gmt/instant/parse`). To write one, use `fromOffsetInstant` or `formatRfc3339`: every major database reads that ISO 8601 form.
- Fractional seconds are written as Temporal writes them: only the digits needed, with trailing zeros dropped (`.500` → `.5`).

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | plain ISO 8601 datetime string (e.g. "2024-03-15T14:30:00") |

## Returns

SQL timestamp literal, or "" on invalid input

## Examples

```ts
import { formatSqlDateTime } from "@northguild/gmt/plain/format";

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

## Source

[plain/format/formatSqlDateTime.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/plain/format/formatSqlDateTime.ts)
