Home >Database >Mysql Tutorial >Why Does CONVERT_TZ Return NULL in MySQL, and How Can I Fix It?

Why Does CONVERT_TZ Return NULL in MySQL, and How Can I Fix It?

Barbara Streisand
Barbara StreisandOriginal
2024-12-03 06:57:10245browse

Why Does CONVERT_TZ Return NULL in MySQL, and How Can I Fix It?

Understanding "CONVERT_TZ Returns NULL" Error

In MySQL, encountering a "CONVERT_TZ Returns NULL" error can be frustrating, especially when it looks Seems so straight forward. The reason may be that the MySQL time zone table has not yet been loaded into the database.

To load the time zone table, use the following command:

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

In this command:

  • /usr/share/zoneinfo is the time zone information file path.
  • -u root -p allows you to connect to MySQL using the root user identity.
  • mysql is the name of the built-in database used to store MySQL-specific configuration data.

After executing this command, the time zone table will be loaded in the database. You can now run the CONVERT_TZ function again and it will correctly return the converted time.

Note: the mysql_tzinfo_to_sql command may vary depending on your system. Consult the MySQL documentation for details on specific commands.

The above is the detailed content of Why Does CONVERT_TZ Return NULL in MySQL, 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