Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-12-01 · container image postgres:17
The message quotes the value: date/time field value out of range: "30/11/2026". Unlike 22007, the format is recognized; one of the numbers is impossible.
When the problem is the day/month order, PostgreSQL adds HINT: Perhaps you need a different "datestyle" setting. The default DateStyle in the postgres:17 image is ISO, MDY.
01dd/mm/yyyy text read as month/day (DateStyle MDY)
SHOW datestyle returns ISO, MDY, so '30/11/2026' is read as month 30, which does not exist.
Setup
CREATE TABLE orders (id int PRIMARY KEY, order_date date);CREATE TABLEINSERT INTO orders VALUES (1, '30/11/2026');ERROR: 22008: date/time field value out of range: "30/11/2026"
LINE 1: INSERT INTO orders VALUES (1, '30/11/2026');
^
HINT: Perhaps you need a different "datestyle" setting.SHOW datestyle; DateStyle
-----------
ISO, MDY
(1 row)State the format explicitly with to_date('30/11/2026', 'DD/MM/YYYY'). It is stored as 2026-11-30 regardless of DateStyle. Changing DateStyle was not tested here.
INSERT INTO orders VALUES (1, to_date('30/11/2026', 'DD/MM/YYYY'));
SELECT * FROM orders;INSERT 0 1
id | order_date
----+------------
1 | 2026-11-30
(1 row)02A day that does not exist, such as November 31
A month-end date is built by appending '-31' to '2026-11'. November has 30 days, so '2026-11-31'::date fails.
Setup
CREATE TABLE closings (ym text PRIMARY KEY, close_date date);CREATE TABLEINSERT INTO closings VALUES ('2026-11', ('2026-11' || '-31')::date);ERROR: 22008: date/time field value out of range: "2026-11-31"SELECT (date_trunc('month', date '2026-11-01') + interval '1 month - 1 day')::date AS month_end; month_end
------------
2026-11-30
(1 row)Compute the month end: (date_trunc('month', d) + interval '1 month - 1 day')::date returns 2026-11-30.
INSERT INTO closings VALUES ('2026-11', (date_trunc('month', ('2026-11' || '-01')::date) + interval '1 month - 1 day')::date);
SELECT * FROM closings;INSERT 0 1
ym | close_date
---------+------------
2026-11 | 2026-11-30
(1 row)03More than 24 hours stored in a time column
The column holds total hours worked as time, but time is a time of day, so '25:30' is out of range.
Setup
CREATE TABLE work_log (emp_id int, work_day date, worked time);CREATE TABLEINSERT INTO work_log VALUES (7, '2026-11-30', '25:30');ERROR: 22008: date/time field value out of range: "25:30"
LINE 1: INSERT INTO work_log VALUES (7, '2026-11-30', '25:30');
^ALTER TABLE work_log ALTER COLUMN worked TYPE interval;ALTER TABLEUse interval for durations: after ALTER COLUMN worked TYPE interval, '25:30' is stored as 25:30:00 and extract(epoch …) / 3600 gives 25.5 hours.
INSERT INTO work_log VALUES (7, '2026-11-30', '25:30');
SELECT emp_id, worked, extract(epoch FROM worked) / 3600 AS hours FROM work_log;INSERT 0 1
emp_id | worked | hours
--------+----------+---------------------
7 | 25:30:00 | 25.5000000000000000
(1 row)04Casting Unix epoch seconds text with ::timestamp
A string like '1764460800' from an API or log is not a date. Casting it with ::timestamp gives 22008, and the HINT mentions datestyle, but DateStyle is not the problem.
Setup
CREATE TABLE events (id int PRIMARY KEY, created_at timestamp);
CREATE TABLE events_raw (id int, created_at text);
INSERT INTO events_raw VALUES (1, '1764460800'), (2, '1764547200');CREATE TABLE
CREATE TABLE
INSERT 0 2INSERT INTO events SELECT id, created_at::timestamp FROM events_raw;ERROR: 22008: date/time field value out of range: "1764460800"
HINT: Perhaps you need a different "datestyle" setting.SELECT created_at, to_timestamp(created_at::bigint) AT TIME ZONE 'UTC' AS utc_time FROM events_raw; created_at | utc_time
------------+---------------------
1764460800 | 2025-11-30 00:00:00
1764547200 | 2025-12-01 00:00:00
(2 rows)Convert it to a number and use to_timestamp(created_at::bigint). It returns timestamptz, so here AT TIME ZONE 'UTC' was used for the timestamp column, storing 2025-11-30 00:00:00.
INSERT INTO events SELECT id, to_timestamp(created_at::bigint) AT TIME ZONE 'UTC' FROM events_raw;
SELECT * FROM events ORDER BY id;INSERT 0 2
id | created_at
----+---------------------
1 | 2025-11-30 00:00:00
2 | 2025-12-01 00:00:00
(2 rows)05Month and day swapped in the to_date format
Reading US-style '11/30/2026' with 'DD/MM/YYYY' makes 30 the month. Because the error comes from to_date, there is no HINT or LINE, only the value.
Setup
CREATE TABLE shipments (id int PRIMARY KEY, ship_date date);CREATE TABLEINSERT INTO shipments VALUES (1, to_date('11/30/2026', 'DD/MM/YYYY'));ERROR: 22008: date/time field value out of range: "11/30/2026"SELECT to_date('11/30/2026', 'MM/DD/YYYY') AS ship_date; ship_date
------------
2026-11-30
(1 row)Use the format that matches the data, 'MM/DD/YYYY', and it is stored as 2026-11-30.
INSERT INTO shipments VALUES (1, to_date('11/30/2026', 'MM/DD/YYYY'));
SELECT * FROM shipments;INSERT 0 1
id | ship_date
----+------------
1 | 2026-11-30
(1 row)FAQ
How do I fix date/time field value out of range in PostgreSQL?
Check the quoted value. For dd/mm/yyyy use to_date with a format, for impossible days compute the date instead of building a string, and use interval for durations over 24 hours.
What does the HINT about datestyle mean?
PostgreSQL read your day as a month because DateStyle is MDY. Using to_date with an explicit format avoids depending on that setting.
How do I get the last day of the month in PostgreSQL?
(date_trunc('month', your_date) + interval '1 month - 1 day')::date
Can a PostgreSQL time column store 25 hours?
No. time is a time of day. Store durations in an interval column, which accepts '25:30'.
How do I convert a Unix timestamp to timestamp in PostgreSQL?
'1764460800'::timestamp fails with 22008. Use to_timestamp(value::bigint), which returns timestamptz, and pick a time zone such as AT TIME ZONE 'UTC' for a timestamp column.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12