SQLSTATE 22008 ERROR Class 22: Data Exception

datetime_field_overflow date/time field value out of range: “…” — 22008

PostgreSQL error "date/time field value out of range: "…"" (SQLSTATE 22008): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A date/time value contains a field outside its legal range (month 13, day 32, hour 25, etc.), or the overall value is unrepresentable. PostgreSQL raises SQLSTATE 22008 (datetime_field_overflow).

  • The bad value is quoted; a HINT may mention DateStyle.
  • Often an ambiguous day/month order misread under the current DateStyle.
  • Common in imports of mixed-format dates.

What the server log shows

ERROR:  date/time field value out of range: "2026-02-30"
HINT:  Perhaps you need a different "datestyle" setting.

Why PostgreSQL raises this — what the manual says

As Section 8.5.1 Date/Time Input explains:

Each date/time field must fall within its natural range (for example months 1-12, or a day number valid for the given month); a field such as month 13 or day 32 is rejected as a field value out of range.

After tokenizing the input, PostgreSQL validates each field against its legal range and the calendar. An impossible date (Feb 30) or an out-of-range field fails with 22008.

Common causes

  • Impossible calendar dates (e.g. Feb 30, day 32).
  • Day/month transposition under the active DateStyle.
  • Out-of-range time fields.

How to fix it

  1. Send ISO 8601 dates to remove ambiguity.
  2. Set the correct DateStyle (e.g. SET datestyle = 'ISO, DMY';).
  3. Validate dates upstream; use to_date()/to_timestamp() with an explicit format.

Related & next steps

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

Was this helpful?