Converting UTC Dates to Local Time Zones in MySQL Queries
To convert UTC timestamps to local time zones in your MySQL queries, you can use the CONVERT_TZ() function. However, it's important to note that using this function may not always be successful.
Why CONVERT_TZ() Might Fail
If CONVERT_TZ() is not working for you, there are a few possible reasons:
Query Example Using CONVERT_TZ()
The following query converts a timestamp column called displaytime to the MET time zone:
SELECT CONVERT_TZ(displaytime, '+00:00', '+04:00');
Checking Time Zone Tables
To verify if your time zone tables are initialized, execute the following queries:
SELECT * FROM mysql.time_zone; SELECT * FROM mysql.time_zone_name;
Initializing Time Zone Tables
If the time zone tables are empty, use the following command to load them:
mysql_tzinfo_to_sql /usr/share/zoneinfo
Once the time zone tables are initialized, try using CONVERT_TZ() again. If you still encounter issues, consult the MySQL documentation for more detailed troubleshooting steps:
以上是为什么 CONVERT_TZ() 在我的 MySQL 查询中不起作用?的详细内容。更多信息请关注PHP中文网其他相关文章!