Incident Response

MySQL ERROR 1292: Incorrect datetime value

Zero dates, February 30th, a trailing Z from JavaScript or an empty CSV field: MySQL refuses the value. Here is how to find which one it is and fix it without breaking big tables.

· 14 min read · AG Data Team

MySQL ERROR 1292: Incorrect datetime value means MySQL was handed a string it would not accept as a DATE, DATETIME or TIMESTAMP, and strict SQL mode turned that into a hard error instead of a warning.

mysql> INSERT INTO orders (created_at) VALUES ('0000-00-00 00:00:00');
ERROR 1292 (22007): Incorrect datetime value: '0000-00-00 00:00:00' for column 'created_at' at row 1

mysql> INSERT INTO orders (ship_date) VALUES ('2026-02-30');
ERROR 1292 (22007): Incorrect date value: '2026-02-30' for column 'ship_date' at row 1

The server error reference lists code 1292 as ER_TRUNCATED_WRONG_VALUE, SQLSTATE 22007 (invalid datetime format). Its generic text is "Truncated incorrect %s value", but when the bad value is headed for a column you see the more useful form above, with the column name and the row number. In a WHERE clause the same bad literal can surface as ERROR 1525 Incorrect DATETIME value instead. Either way the cause is in the value, not the table, so the first job is to see exactly what string arrived.

The four usual causes

In our experience almost every 1292 comes from one of these.

ISO 8601 strings and time zones

A common modern variant comes from JavaScript and JSON APIs. new Date().toISOString() produces '2026-11-29T10:00:00.000Z', and MySQL rejects it. The T separator is fine, as the date and time literals page says, and so are fractional seconds. The problem is the trailing Z.

MySQL does accept a numeric offset appended to the time, such as '2026-11-29 10:00:00+02:00'. The offset uses the same format as the time_zone variable, the hour needs a leading zero, '-00:00' is rejected and named zones like 'Europe/Riga' are not allowed. The value is converted to the session time zone on insert, so the offset itself is not stored.

-- rejected: not a MySQL datetime literal
'2026-11-29T10:00:00Z'          -- JavaScript toISOString(), trailing Z
'29/11/2026 10:00'              -- day/month/year
'Sun, 29 Nov 2026 10:00:00 GMT' -- HTTP date
''                              -- empty string from a form or CSV

-- accepted
'2026-11-29 10:00:00'
'2026-11-29T10:00:00'           -- T instead of a space is fine
'2026-11-29 10:00:00+02:00'     -- numeric offset, converted on insert

-- parse foreign formats explicitly
INSERT INTO orders (created_at)
VALUES (STR_TO_DATE('29/11/2026 10:00', '%d/%m/%Y %H:%i'));

The cleanest fix is to send a plain 'YYYY-MM-DD hh:mm:ss' value from the application, or let the driver bind a native date object. Decide once whether the database stores UTC, and set the session time_zone accordingly. For TIMESTAMP columns MySQL converts from the session time zone to UTC for storage and back on read, as the DATETIME documentation explains. DATETIME stores exactly what it is given.

How to fix it

  1. Log the exact value the application sent. The error message quotes it, which is often enough.
  2. Check the SQL mode of the failing session, not only of the server. Connection pools, ORMs and migration tools sometimes set their own sql_mode.
  3. Fix the value at the source: send NULL for "unknown" (and make the column nullable), validate dates in the application, and parse non-standard formats with STR_TO_DATE(). Per the function reference, STR_TO_DATE() returns NULL with a warning when the string cannot be parsed, so pair it with a NOT NULL column or a check if you need a hard failure.
  4. Use a DATETIME instead of a TIMESTAMP for values outside 1970 to 2038.
-- what is this session enforcing?
SELECT @@SESSION.sql_mode;

-- rows with zero dates or zero month/day parts
SELECT id, CAST(created_at AS CHAR) AS raw_value
FROM orders
WHERE MONTH(created_at) = 0 OR DAY(created_at) = 0
LIMIT 100;

Do not "fix" it by removing modes. Dropping NO_ZERO_DATE or strict mode makes the error go away, but the SQL mode documentation is clear about what happens next: without strict mode invalid dates are stored as '0000-00-00' with only a warning, and garbage strings are truncated. ALLOW_INVALID_DATES lets '2026-02-30' into DATE and DATETIME columns as is. Both NO_ZERO_DATE and NO_ZERO_IN_DATE are deprecated, and MySQL says their effect is expected to become part of strict mode, so relying on turning them off is a short-term bet. The related truncation case is covered in our article on ERROR 1265 Data truncated for column.

CSV imports with LOAD DATA

Bulk loads hit 1292 on empty fields and local date formats. In strict mode one bad line stops the whole LOAD DATA, and on InnoDB nothing from that statement is kept. The LOAD DATA documentation lets you read a field into a user variable and transform it in the SET clause, which handles both problems in one pass:

LOAD DATA INFILE '/var/lib/mysql-files/orders.csv'
INTO TABLE orders
FIELDS TERMINATED BY ','
(id, @created)
SET created_at = CASE
  WHEN @created = '' THEN NULL
  WHEN @created LIKE '__.__.____' THEN STR_TO_DATE(@created, '%d.%m.%Y')
  ELSE @created
END;

Avoid the shortcut of LOAD DATA ... IGNORE for dates. It turns the errors into warnings, and rows you cannot parse quietly get a zero date or NULL, which is usually worse than a failed import.

Legacy zero dates on large tables

The hardest 1292 cases appear on big, old tables after an upgrade or a move to a new server with the default SQL mode. The data loaded fine and reads fine, but now ordinary work fails:

The safe order on a large table is: change the default and nullability of the column, update the application so it stops writing zero dates, clean existing rows in primary key batches while watching replica lag, confirm the count is zero, and only then run the type change or the upgrade. Batch size depends on row width and load; in our experience a few thousand to tens of thousands of rows per statement keeps locks short.

-- 1. make the column nullable first if zero dates meant "unknown"
--    (or pick a real sentinel value your application understands)

-- 2. fix legacy rows in primary-key ranges, not in one statement
UPDATE orders
SET created_at = NULL
WHERE id BETWEEN 1 AND 50000
  AND (MONTH(created_at) = 0 OR DAY(created_at) = 0);

-- 3. repeat for the next range, check replica lag between batches,
--    then confirm nothing is left before the schema change
SELECT COUNT(*) FROM orders
WHERE MONTH(created_at) = 0 OR DAY(created_at) = 0;

Zero dates are one of the items we check on every major upgrade; the rest of the list is in our guide to upgrading MySQL 8.0 to 8.4.

Key takeaways

MySQL Errors Data quality Upgrades
Work with us

Zero dates blocking an upgrade or a migration?

We find and clean invalid dates in large MySQL tables, align SQL modes across servers and run the schema changes without downtime.

Get in touch More from the blog