# isValidSqlDateTime

Industry: Core

## Signature

```ts
isValidSqlDateTime(value: string): boolean
isValidSqlDateTime(value: void | {} | null | undefined): boolean
isValidSqlDateTime(value: unknown): value is string
```

Return 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 `parseSqlDateTime` returns a plain string for the same value: the validator and the parser read through one internal core, so the two cannot disagree.
- **Grammar:** SQL-92 §5.3 `<timestamp string>` and the ODBC `ts` escape, as `sqlDateTime` matches: a single space separator, a four-digit year `0001`–`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 `sqlDateTime` pattern 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 `T` separator, a `Z` and an offset are false: SQL's offset-carrying `TIMESTAMP WITH TIME ZONE` literal is checked by `isValidSqlOffsetDateTime`.
- Read the value with `parseSqlDateTime`; write one with `formatSqlDateTime`.
- A value that is not a string, a `String` object included, returns `false`. A `true` result narrows an `unknown` value to `string`.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | any value; a string is checked as a SQL timestamp literal |

## Returns

boolean indicating validity

## Examples

```ts
import { isValidSqlDateTime } from "@northguild/gmt/plain/validate";

isValidSqlDateTime("2024-03-15 14:30:00") // true
```

## Source

[plain/validate/isValidSqlDateTime.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/plain/validate/isValidSqlDateTime.ts)
