Troubleshooting the "convert_tz returns null" Error
When attempting to utilize the convert_tz function in MySQL Workbench, it may return a null value, leaving users puzzled. This issue typically arises when the time zone table has not been loaded into MySQL.
To resolve this problem, follow these steps:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
In this command, "mysql" represents the built-in database that stores MySQL-specific configuration data. By executing this command, you populate the time zone table with information from the local system.
Once the time zone table has been loaded, the convert_tz function should function correctly. For instance, the following query will now produce the expected result:
SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','Asia/Jakarta') AS time
This query converts the specified timestamp from UTC to Asia/Jakarta time, assuming that the time zone table is now populated.
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!