PostgreSQL 22008: date/time field value out of range
A date or time had a field outside its valid range, such as month 13 or day 31 in a 30-day month, or a day/month order mix-up.
- SQLSTATE
22008- Name
datetime_field_overflow- Category
- Data Exception
What it means
The input looked like a date or time, but one of its fields is impossible: a month above 12, a day that doesn't exist in that month, an hour above 24. 22008 (datetime_field_overflow) also covers results outside the representable range, such as timestamp out of range.
When the value is a numeric date like 13/01/2026, PostgreSQL adds a hint that you may need a different DateStyle, because it read 13 as the month.
Common causes
- Day and month swapped relative to the session's
DateStyle. - Invalid calendar dates in source data, such as February 30.
- Date arithmetic that produces a value beyond the supported range.
How to fix it
-
Use ISO 8601 dates (
YYYY-MM-DD), which are never ambiguous. -
If the data is day-first, say so, or parse it with an explicit format.
SET DateStyle = 'ISO, DMY'; SELECT '13/01/2026'::date; -- or SELECT to_date('13/01/2026', 'DD/MM/YYYY'); -
Find bad rows in a staging table before converting them (PostgreSQL 16 and later).
SELECT raw_date FROM staging WHERE NOT pg_input_is_valid(raw_date, 'date');
Reproduce it safely
SELECT '2026-02-30'::date; -- ERROR: date/time field value out of range: "2026-02-30"
Related errors
22007invalid datetime format22003numeric value out of range242SQL Server: Out-of-range date conversion1292MySQL: Truncated incorrect valueORA-01843Oracle: not a valid month
More data exception errors
22021invalid byte sequence for encoding22012division by zero22023invalid parameter value22001value too long for type22P02invalid input syntax for type
The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.
Work on PostgreSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.