1465
MariaDBERRORNotableData TypesHIGH confidence

Datetime field overflow in date/time function

Production Risk

Low — query returns an error or NULL; validate date inputs.

What this means

ER_DATETIME_FUNCTION_OVERFLOW (1465, SQLSTATE HY000) is raised when a date or time calculation produces a result outside the valid range for the DATETIME type.

Why it happens
  1. 1DATE_ADD or DATE_SUB producing a date outside the range 1000-01-01 to 9999-12-31
  2. 2Arithmetic on TIMESTAMP values producing results outside the valid TIMESTAMP range
How to reproduce
trigger — this will error
trigger — this will error
SELECT DATE_ADD('9999-12-31', INTERVAL 1 DAY);
-- Result would exceed max DATETIME

expected output

ERROR 1465 (HY000): Datetime function: datetime field overflow

Fix

Check date ranges before arithmetic

Check date ranges before arithmetic
-- Validate that the result will be within range:
SELECT CASE
  WHEN DATE_ADD(my_date, INTERVAL 1 YEAR) > '9999-12-31'
  THEN NULL
  ELSE DATE_ADD(my_date, INTERVAL 1 YEAR)
END FROM my_table;

Why this works

Guard against out-of-range results with conditional logic or application-level validation.

Sources
Official documentation ↗

MySQL 8.0 — 1465 ER_DATETIME_FUNCTION_OVERFLOW

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors