Skip to content

formatSqlDateTime

  • The core functions, which every industry uses.
formatSqlDateTime(value: string): string

Format 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 ODBC ts escape, which parseSqlDateTime reads: 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 ZONE literal (YYYY-MM-DD HH:MM:SS±HH:MM, e.g. PostgreSQL) is read by parseSqlOffsetDateTime (@northguild/gmt/instant/parse). To write one, use fromOffsetInstant or formatRfc3339: every major database reads that ISO 8601 form.
  • Fractional seconds are written as Temporal writes them: only the digits needed, with trailing zeros dropped (.500 → .5).
ParameterTypeDescription
valuestringplain ISO 8601 datetime string (e.g. “2024-03-15T14:30:00”)

SQL timestamp literal, or "" on invalid input

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

plain/format/formatSqlDateTime.ts

Accessibility
© 2026 NorthGuild · Licences

Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.