Converting UTC Dates to Local Time Zones in MySQL Select Queries
Question:
How can I modify a MySQL query to convert a UTC timestamp column, "displaytime," into the local time zone?
Answer 1:
Use the CONVERT_TZ() function as follows:
SELECT CONVERT_TZ(displaytime, 'GMT', 'MET');
Answer 2:
Ensure that your timezone tables are initialized. Use the mysql_tzinfo_to_sql program to populate them:
shell> mysql_tzinfo_to_sql /usr/share/zoneinfo
Once initialized, you can use the CONVERT_TZ() function as described above.
Additional Notes:
SELECT * FROM mysql.time_zone; SELECT * FROM mysql.time_zone_name;
The above is the detailed content of How to Convert UTC Dates to Local Time Zones in MySQL Select Queries?. For more information, please follow other related articles on the PHP Chinese website!