Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Databases and Redis

CONVERT_TZ() gives NULL instead of the converted time

Your error

SELECT CONVERT_TZ(created_at, 'UTC', 'Europe/Berlin') returns NULL for every row1 more line it can show

Fix it fast

Most common cause, 1 of 3

The time zone tables were never loaded

Load the system zoneinfo with mysql_tzinfo_to_sql, then restart the server so it drops cached zone data.

Fix
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
sudo systemctl restart mysql    # use the service name of your install

# Windows: unpack the downloaded package, then load the file it contains
mysql -u root -p mysql < file_name
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

CONVERT_TZ() returns NULL when any argument is NULL or invalid. With named zones such as 'UTC' or 'Europe/Berlin', the mysql time zone tables must be loaded first; SELECT COUNT(*) FROM mysql.time_zone_name returns 0 until they are. Load them with mysql_tzinfo_to_sql and restart, use offsets like '+00:00', and check the datetime value itself. MySQL 8.4 and 9.7.

  • Applies to MySQL 8.4 LTS, MySQL 9.7 LTS, Linux with /usr/share/zoneinfo, Windows, official mysql Docker image
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Count the named zones the server knows, then run one conversion that uses offsets only. A zero count with a working offset query points to cause 1; a non-zero count points to causes 2 or 3.

Run this first
SELECT COUNT(*) FROM mysql.time_zone_name;
SELECT CONVERT_TZ('2026-11-21 12:00:00', '+00:00', '+01:00');

Then find the line you see in this list and open its fix:

  1. 1The time zone tables were never loadedSELECT COUNT(*) FROM mysql.time_zone_name returns 0, and SET time_zone = 'UTC' fails with error 1298
  2. 2The zone argument is not a name the tables hold, or not a valid offsetThe tables are loaded, offsets such as '+01:00' convert fine, and only one particular zone string gives NULL
  3. 3The datetime value itself is NULL or not a valid dateThe same zones work in a test with a literal date, but some rows of the table return NULL

What does the error look like?

  • SELECT CONVERT_TZ(created_at, 'UTC', 'Europe/Berlin') returns NULL for every row
  • ERROR 1298 (HY000): Unknown or incorrect time zone: 'UTC'

Cause 1 of 3

The time zone tables were never loaded

You seeSELECT COUNT(*) FROM mysql.time_zone_name returns 0, and SET time_zone = 'UTC' fails with error 1298

Check

CONVERT_TZ returns NULL for a named zone when the server has no time zone data: named zones work only after the time zone tables in the mysql database are created and filled. Until then even 'UTC' is an unknown name, while numeric offsets keep working. In the official mysql Docker image, the entrypoint script loads this data automatically unless MYSQL_INITDB_SKIP_TZINFO is set to a non-empty value.

Check
SELECT COUNT(*) FROM mysql.time_zone_name;
docker inspect --format '{{.Config.Env}}' my-mysql | tr ' ' '\n' | grep TZINFO

Fix

Load the system zoneinfo with mysql_tzinfo_to_sql, then restart the server so it drops cached zone data. On Windows, which has no zoneinfo database, load the SQL package from the MySQL time zone download page instead.

Fix
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
sudo systemctl restart mysql    # use the service name of your install

# Windows: unpack the downloaded package, then load the file it contains
mysql -u root -p mysql < file_name

Verify

The count is above zero and the named conversion returns a datetime.

Verify
SELECT COUNT(*) FROM mysql.time_zone_name;
SELECT CONVERT_TZ('2026-11-21 12:00:00', 'UTC', 'Europe/Berlin');

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 3

The zone argument is not a name the tables hold, or not a valid offset

You seeThe tables are loaded, offsets such as '+01:00' convert fine, and only one particular zone string gives NULL

Check

Any invalid argument makes CONVERT_TZ return NULL. A name must match an entry in mysql.time_zone_name (case does not matter). An offset must look like +HH:MM or -H:MM with a sign and a colon, within '-13:59' to '+14:00', so forms such as '+5' or '+14:30' are rejected.

Check
SELECT Name FROM mysql.time_zone_name WHERE Name LIKE 'Europe/Ber%';

Fix

Use the exact region name the query lists, or write the offset in the documented form.

Fix
SELECT CONVERT_TZ(created_at, '+00:00', '+05:30') FROM orders;
SELECT CONVERT_TZ(created_at, 'UTC', 'Asia/Kolkata') FROM orders;

Verify

The conversion returns a value for the zone that failed before.

Verify
SELECT CONVERT_TZ('2026-11-21 12:00:00', '+00:00', '+05:30');

Confirmed by dev.mysql.com

Did this fix it?

Cause 3 of 3

The datetime value itself is NULL or not a valid date

You seeThe same zones work in a test with a literal date, but some rows of the table return NULL

Check

CONVERT_TZ also returns NULL when its first argument is NULL or cannot be read as a datetime. Rows with an empty column, or a string column holding values such as '2026-02-30', come back as NULL even though the zones are fine.

Check
SELECT id, created_at
FROM orders
WHERE created_at IS NULL
   OR CAST(created_at AS DATETIME) IS NULL
LIMIT 20;

Fix

Clean or skip the rows the query found, and store dates in a DATETIME or TIMESTAMP column rather than in text.

Fix
SELECT id, CONVERT_TZ(created_at, 'UTC', 'Europe/Berlin') AS local_time
FROM orders
WHERE created_at IS NOT NULL;

Verify

No rows remain where a stored date returns NULL.

Verify
SELECT COUNT(*) FROM orders WHERE created_at IS NOT NULL AND CONVERT_TZ(created_at, 'UTC', 'Europe/Berlin') IS NULL;

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • Add mysql_tzinfo_to_sql to the provisioning script of every MySQL server that uses named zones, and reload it after tzdata updates.
  • Do not set MYSQL_INITDB_SKIP_TZINFO in Docker deployments whose queries call CONVERT_TZ with zone names.
  • Store timestamps in UTC and convert with named zones only at the edge, so a missing table shows up in one place.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, QistLock, Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.