SQLSTATE 22007 ERROR Class 22: Data Exception

invalid_datetime_format invalid input syntax for type timestamp: “…” — 22007

PostgreSQL error “invalid input syntax for type timestamp: … — 22007” (SQLSTATE 22007): what it means, common causes, and how to fix it.

PG 9.6, 10, 11, 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

Diagnostic Queries

Symptoms

A string could not be parsed as a timestamp. PostgreSQL raises SQLSTATE 22007 (invalid_datetime_format).

  • The timestamp text isn’t in a recognized format.
  • Common with ambiguous or non-ISO date/time strings.
  • Affected by DateStyle for ambiguous inputs.

What the server log shows

ERROR:  invalid input syntax for type timestamp: "2024-13-40 99:99"

Why PostgreSQL raises this — what the manual says

Section 8.5.1 Date/Time Input:

“Date and time input is accepted in almost any reasonable format”

Timestamp parsing validates both format and field ranges. Input that isn’t a recognized format, or has out-of-range fields (month 13, etc.), cannot be interpreted, so PostgreSQL reports 22007.

Common causes

  • A malformed or out-of-range timestamp string.
  • An ambiguous format under the current DateStyle.
  • Locale/format mismatch between the app and the server.

How to fix it

  1. Use ISO 8601: '2024-01-15 13:45:00'.
  2. Set DateStyle appropriately for ambiguous inputs.
  3. Use to_timestamp(text, format) to parse non-standard formats explicitly.

Related & next steps

Reference: PostgreSQL 18 Section 8.5 “Date/Time Types”.

Was this helpful?