formatSql
Signature
Section titled “Signature”formatSql(value: string): stringimport { formatSql } from "@northguild/gmt/plain/format";Format a plain ISO 8601 datetime string as an ANSI SQL / ODBC datetime
- literal — the
YYYY-MM-DD HH:MM:SSform MySQL, SQLite, and standard SQLDATETIME/TIMESTAMPcolumns (without a time zone) accept. - Plain only. SQL’s offset-carrying
TIMESTAMPTZliteral (YYYY-MM-DD HH:MM:SS±HH:MM, e.g. PostgreSQL) is out of scope — this targets the far more common tz-lessDATETIMEcolumn shape. There is no zoned counterpart in this story. - The only change from GMT’s own ISO output is the separator:
Tbecomes a single space. Fractional seconds, when present, are preserved as-is.
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 datetime literal, or “” on invalid input
Examples
Section titled “Examples”formatSql("2024-03-15T14:30:00") // "2024-03-15 14:30:00"formatSql("2024-03-15T14:30:00.500") // "2024-03-15 14:30:00.5"formatSql("invalid") // ""