isValidSqlDateTime
Signature
Section titled “Signature”isValidSqlDateTime(value: string): booleanReturn true when value is a real SQL timestamp literal without a time zone: the YYYY-MM-DD HH:MM:SS[.fff] value of a standard SQL TIMESTAMP or a MySQL/SQLite DATETIME column. It checks one date-and-time value, not a SQL statement.
- True exactly when
parseSqlDateTimereturns a plain string for the same value: the validator calls the parser, so the two cannot disagree. - Grammar: SQL-92 §5.3
<timestamp string>and the ODBCtsescape, assqlDateTimematches: a single space separator, a four-digit year0001–9999, two-digit month, day, hour, minute and second (seconds are required), and an optional.followed by up to 9 fraction digits. - Checks the calendar as well as the shape. The
sqlDateTimepattern proves the shape alone, so it matches a day that does not exist: 30 February, 29 February in a common year and 31 June are false here. - False for a second of 60: GMT rejects leap seconds.
- Plain only. A
Tseparator, aZand an offset are false: SQL’s offset-carryingTIMESTAMP WITH TIME ZONEliteral is out of scope. - False for a non-string. Read the value with
parseSqlDateTime; write one withformatSqlDateTime.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | candidate SQL timestamp literal |
Returns
Section titled “Returns”boolean indicating validity
Examples
Section titled “Examples”import { isValidSqlDateTime } from "@northguild/gmt/plain/validate";
isValidSqlDateTime("2024-03-15 14:30:00") // true