Configure a session-level time zone or a global time zone
You can configure a session-level time zone or a global time zone for your cluster using thetime_zone parameter.
- To configure a session-level time zone, execute the command
SET time_zone = 'xxx';. You can configure different time zones for different sessions. The time zone setting becomes invalid if you disconnect with FEs. - To configure a global time zone, execute the command
SET global time_zone = 'xxx';. The time zone setting is persisted in FEs and is valid even if you disconnect with FEs.
Note Before you load data into the database, modify the global time zone of your cluster to the same value of thesystem_time_zoneparameter. Otherwise, after data loading, data of the DATE type are incorrect. Thesystem_time_zoneparameter refers to the time zone of the machines that are used to host FEs. When the machines are started, the time zone of the machines is recorded as the value of this parameter. You cannot manually configure this parameter.
Time zone format
The value of thetime_zone parameter is not case-sensitive. The value of the parameter can be in one of the following formats.
For more information about time zone format, see List of tz database time zones.
Note Time zone abbreviations are not supported except for CST. If you set the value oftime_zonetoCST, the database convertsCSTintoAsia/Shanghai.
Default time zone
The default value of thetime_zone parameter is Asia/Shanghai.
View time zone settings
To view the time zone setting, run the following command.Impacts of time zone settings
- Time zone settings affect the time values returned by the SHOW LOAD and SHOW BACKENDS statements. However, the settings do not affect the value specified in the
LESS THANclause when the partitioning columns specified in CREATE TABLE statement are of the DATE or DATETIME type. The settings also do not affect data of the DATE and DATETIME types. - Time zone settings affect the display and storage of the following functions:
- from_unixtime: returns a date and time of your specified time zone based on a specified UTC timestamp. For example, if the global time zone of your cluster is
Asia/Shanghai,select FROM_UNIXTIME(0);returns1970-01-01 08:00:00. - unix_timestamp: returns a UTC timestamp based on the date and time of your specified time zone. For example, if the global time zone of your cluster is
Asia/Shanghai,select UNIX_TIMESTAMP('1970-01-01 08:00:00');returns0. - curtime: returns the current time of your specified time zone. For example, if the current time of a specified time zone is 16:34:05.
select CURTIME();returns16:34:05. - now: returns the current date and time of your specified time zone. For example, if the current date and time of a specified time zone is 2021-02-11 16:34:13,
select NOW();returns2021-02-11 16:34:13. - convert_tz: converts the date and time from one time zone to another. For example,
select CONVERT_TZ('2021-08-01 11:11:11', 'Asia/Shanghai', 'America/Los_Angeles');returns2021-07-31 20:11:11.
- from_unixtime: returns a date and time of your specified time zone based on a specified UTC timestamp. For example, if the global time zone of your cluster is