parseSqlDateTime
Signature
Section titled “Signature”parseSqlDateTime(value: string): stringParse 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 — into a plain ISO 8601 datetime string.
- Grammar: SQL-92 §5.3
<timestamp string>and the ODBCtsescape, assqlDateTimematches: a space separator, a four-digit year0001–9999(no sign, no expanded year), two-digit month, day, hour, minute and second (seconds are required), and an optional.followed by up to 9 fraction digits. - Plain only. SQL’s offset-carrying
TIMESTAMP WITH TIME ZONEliteral is out of scope; seeformatSqlDateTime’s JSDoc. - The fraction is written as
Temporal.PlainDateTime#toStringwrites it: trailing zeros are dropped (.500→.5,.000→ none), and a.with no digits is dropped.Temporal.PlainDateTime.fromproves the value is a real calendar date and time.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | SQL timestamp 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”import { parseSqlDateTime } from "@northguild/gmt/plain/parse";
parseSqlDateTime("2024-03-15 14:30:00") // "2024-03-15T14:30:00"