SQLSTATE 22007Severity lowLab verified

Incident brief

Invalid datetime format

A text value was cast to a date/time type, but PostgreSQL couldn't parse it as any recognized date/time format at all.

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
Invalid datetime format
What triggers it
Cast plain, unparseable text to date.
The fix
Send dates in ISO 8601 format (YYYY-MM-DD) — the manual's own recommended, unambiguous format.
Proof
Reproduced on PostgreSQL 16.14 → Casting plain garbage text to date was rejected with SQLSTATE 22007. The session was unaffected afterward.

The fix

What to do right now

The immediate, application-level response to this error.

  • Send dates in ISO 8601 format (YYYY-MM-DD) — the manual's own recommended, unambiguous format.
  • Validate the string is even shaped like a date in application code before sending it to PostgreSQL.
  • Don't confuse this with 22008 — see the premium test for the difference between 'unreadable' and 'reads fine but doesn't exist'.
Fix — SQL
SELECT '1999-01-08'::date;

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Reviewed by
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed