parseSql
Signature
Section titled “Signature”parseSql(value: string): stringimport { parseSql } from "@northguild/gmt/plain/parse";Parse an ANSI SQL / ODBC datetime literal — the YYYY-MM-DD HH:MM:SS form
- MySQL, SQLite, and standard SQL
DATETIME/TIMESTAMPcolumns (without a time zone) use — into a plain ISO 8601 datetime string. - Plain only. SQL’s offset-carrying
TIMESTAMPTZliteral is out of scope; seeformatSql’s JSDoc. - Requires the space separator and 2-digit zero-padded month/day/hour; unlike
parseRfc2822’s lenient 1-2 digit day, a single-digit field is rejected — SQL’s literal grammar has no variable-width form to accept. - Fractional seconds, when present, are preserved as-is; the regex only proves shape —
Temporal.PlainDateTime.fromproves the value is a real calendar date/time.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
SQL datetime literal (e.g. “2024-03-15 14:30:00”) |
Returns
Section titled “Returns”plain ISO 8601 datetime string, or “” on invalid input
Examples
Section titled “Examples”parseSql("2024-03-15 14:30:00") // "2024-03-15T14:30:00"parseSql("2024-03-15 14:30:00.5") // "2024-03-15T14:30:00.5"parseSql("2024-03-15T14:30:00") // "" (wrong separator)parseSql("not a date") // ""