Home >Database >Mysql Tutorial >Why is MySQL's CONVERT_TZ Function Returning NULL and How Can I Fix It?

Why is MySQL's CONVERT_TZ Function Returning NULL and How Can I Fix It?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-03 15:36:11230browse

Why is MySQL's CONVERT_TZ Function Returning NULL and How Can I Fix It?

MySQL CONVERT_TZ Function Returning Null

Problem:

When executing the following query:

SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','Asia/Jakarta') AS time

in MySQL Workbench on Ubuntu 12.04, NULL is returned.

Solution:

This issue occurs when the time zone table has not been loaded into MySQL. To resolve it, execute the following command:

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

where "mysql" is the name of the built-in database used for MySQL configuration data. This command loads the time zone information into the MySQL database, allowing the CONVERT_TZ function to work properly.

The above is the detailed content of Why is MySQL's CONVERT_TZ Function Returning NULL and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn