ERROR: date/time field value out of range: "25/12/2026" with the hint
Perhaps you need a different "DateStyle" setting means PostgreSQL read the date
as month/day/year, and 25 is not a month. Send the date as 2026-12-25, or parse
it with to_date('25/12/2026', 'DD/MM/YYYY').
The default DateStyle in the test container was ISO, MDY, so
25/12/2026 failed with 22008 while 2026-12-25 was stored. A
string that is not a date at all failed with the sister code 22007,
invalid input syntax for type date. 25/12/2026 is fixed by an ISO
date or an explicit format; a stray character or a day that does not exist has to be
corrected at the source.
The error
SHOW datestyle;
DateStyle
-----------
ISO, MDY
(1 row)
INSERT INTO visit VALUES (1, 'Maria Garcia', '25/12/2026');
psql:/tmp/f22008.sql:4: ERROR: 22008: date/time field value out of range: "25/12/2026"
LINE 1: INSERT INTO visit VALUES (1, 'Maria Garcia', '25/12/2026');
^
HINT: Perhaps you need a different "DateStyle" setting.
LOCATION: DateTimeParseError, datetime.c:4228
Two more inputs from the same script, one with a stray character and one with a day that does not exist:
INSERT INTO visit VALUES (2, 'David Chen', '12-31-2026x');
psql:/tmp/f22008.sql:5: ERROR: 22007: invalid input syntax for type date: "12-31-2026x"
LINE 1: INSERT INTO visit VALUES (2, 'David Chen', '12-31-2026x');
^
LOCATION: DateTimeParseError, datetime.c:4262
INSERT INTO visit VALUES (3, 'Aiko Tanaka', '2026-02-30');
psql:/tmp/f22008.sql:6: ERROR: 22008: date/time field value out of range: "2026-02-30"
LINE 1: INSERT INTO visit VALUES (3, 'Aiko Tanaka', '2026-02-30');
^
LOCATION: DateTimeParseError, datetime.c:4221
Why it happens
A date typed as text is read according to DateStyle. With MDY the
first number of 25/12/2026 is the month, 25 is out of range, and the error says
so with the DateStyle hint. February 30 also gave 22008, but without the hint, because the
date is out of range in any order. 12-31-2026x gave 22007 because the trailing
x makes the text unreadable as a date.
The error is the lucky case. In a follow-up test, '05/12/2026'::date under
ISO, MDY returned 2026-05-12, May 12, with no error, and under
ISO, DMY it returned 2026-12-05. A day-first file with small day
numbers is stored wrong without a word.
The fix
INSERT INTO visit VALUES (4, 'Maria Garcia', '2026-12-25');
INSERT 0 1
INSERT INTO visit VALUES (5, 'David Chen', to_date('25/12/2026', 'DD/MM/YYYY'));
INSERT 0 1
SET datestyle = 'ISO, DMY';
SET
INSERT INTO visit VALUES (6, 'Aiko Tanaka', '25/12/2026');
INSERT 0 1
SELECT * FROM visit ORDER BY id;
id | patient | visit_date
----+--------------+------------
4 | Maria Garcia | 2026-12-25
5 | David Chen | 2026-12-25
6 | Aiko Tanaka | 2026-12-25
(3 rows)
All three rows hold December 25. The ISO form YYYY-MM-DD is the fix to prefer:
it was read as December 25 under both ISO, MDY and ISO, DMY. to_date with an
explicit pattern is the fix when the source file is day-first and you cannot change it.
SET datestyle = 'ISO, DMY' worked too, but it changes how later dates in
that session are read: 05/12/2026 became December 5 after it. Fix 22007 inputs at the source: the stray character has to go.
How it was reproduced
A postgres:18 container (PostgreSQL 18.4, Debian 18.4-1.pgdg13+1) on Docker
Engine 29.9.2, database lab, with a table visit (id int, patient text,
visit_date date) and fictional names. The script f22008.sql ran with
docker exec fix8-pg3 sh -c "psql -U postgres -d lab -e -f /tmp/f22008.sql 2>&1",
with \set VERBOSITY verbose at its top for the SQLSTATE codes. The container name
is the test's own.
Frequently asked
- How do I insert a dd/mm/yyyy date into PostgreSQL?
- Use to_date('25/12/2026', 'DD/MM/YYYY') or send the ISO form 2026-12-25. Both were stored as 2026-12-25 in the test, under the default DateStyle ISO, MDY.
- What is the difference between PostgreSQL errors 22007 and 22008 for dates?
- In the test 22008 date/time field value out of range came for 25/12/2026 and for 2026-02-30, and 22007 invalid input syntax for type date came for 12-31-2026x, a string with a stray character.
- Should I change DateStyle to DMY?
- SET datestyle = 'ISO, DMY' made 25/12/2026 work in the test, but it changes how later dates in the session are read: 05/12/2026 became 2026-12-05. 2026-12-25 was read as December 25 under both ISO, MDY and ISO, DMY in the test.
More decoded errors in the Fixes category.