formatSqlDateTime
Signature
Section titled “Signature”formatSqlDateTime(value: string): stringFormat 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 ODBCtsescape, whichparseSqlDateTimereads: 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 ZONEliteral (YYYY-MM-DD HH:MM:SS±HH:MM, e.g. PostgreSQL) is out of scope — this targets the far more common tz-less column shape. There is no zoned counterpart. - Fractional seconds are written as Temporal writes them: only the digits needed, with trailing zeros dropped (
.500→.5).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | plain ISO 8601 datetime string (e.g. “2024-03-15T14:30:00”) |
Returns
Section titled “Returns”SQL timestamp literal, or "" on invalid input
Examples
Section titled “Examples”import { formatSqlDateTime } from "@northguild/gmt/plain/format";
formatSqlDateTime("2024-03-15T14:30:00") // "2024-03-15 14:30:00"