Skip to content

parseSqlDateTime

parseSqlDateTime(value: string): string

Parse 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 ODBC ts escape, as sqlDateTime matches: a space separator, a four-digit year 0001–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 ZONE literal is out of scope; see formatSqlDateTime’s JSDoc.
  • The fraction is written as Temporal.PlainDateTime#toString writes it: trailing zeros are dropped (.500 → .5, .000 → none), and a . with no digits is dropped. Temporal.PlainDateTime.from proves the value is a real calendar date and time.
ParameterTypeDescription
valuestringSQL timestamp literal (e.g. “2024-03-15 14:30:00”)

plain ISO 8601 datetime string, or "" on invalid input

import { parseSqlDateTime } from "@northguild/gmt/plain/parse";
parseSqlDateTime("2024-03-15 14:30:00") // "2024-03-15T14:30:00"
output 

plain/parse/parseSqlDateTime.ts