invalid input syntax for type timestamp: “…”

SQLSTATE 22007 condition invalid_datetime_format class 22 — Data Exception severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

A value being converted to timestamp/timestamptz is not a recognized date-time. PostgreSQL raises SQLSTATE 22007 (invalid_datetime_format) and quotes the bad value.

What the server log shows

ERROR:  invalid input syntax for type timestamp: "2026-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”

The timestamp input parser interprets the string according to DateStyle and field ranges. Out-of-range fields, unparseable text, or empty strings cannot form a valid timestamp and fail with 22007.

Common causes

How to fix it

  1. Send ISO 8601 (YYYY-MM-DD HH:MI:SS) to avoid ambiguity.
  2. Parse non-standard formats with to_timestamp(text, format).
  3. Convert empty strings to NULL; set DateStyle appropriately for the session.

Related & next steps

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