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?

DDD
Release: 2024-12-13 18:15:23
Original
332 people have browsed it

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

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template