- 카테고리:
CONVERT_TIMEZONE¶
타임스탬프를 다른 타임존으로 변환합니다.
구문¶
CONVERT_TIMEZONE( <source_tz> , <target_tz> , <source_timestamp_ntz> )
CONVERT_TIMEZONE( <target_tz> , <source_timestamp> )
인자¶
source_tz
입력 타임스탬프의 타임존을 지정하는 문자열입니다. 타임존이 없는 타임스탬프에 필요합니다(즉, TIMESTAMP_NTZ).
target_tz
입력 타임스탬프를 어느 타임존으로 변환해야 하는지 지정하는 문자열입니다.
source_timestamp_ntz
3개 인자 버전의 경우, 변환할 타임스탬프를 지정하는 문자열입니다(TIMESTAMP_NTZ여야 함).
source_timestamp
2개 버전의 경우, 변환할 타임스탬프를 지정하는 문자열입니다(TIMESTAMP_NTZ 등 모든 타임스탬프 베리언트일 수 있음).
사용법 노트¶
3개 인자 버전의 경우:
결과의 《wallclock》 시간은 입력 타임존의 《wallclock》 입력과 동일한 순간을 나타내지만, 대상 타임존의 시간입니다.
반환 값은 항상 TIMESTAMP_NTZ 형식입니다.
2개 인자 버전의 경우:
source_timestamp
인자는 타임존을 포함하는 것으로 간주됩니다. 값이 TIMESTAMP_TZ 형식인 경우, 타임존은 해당 값에서 가져옵니다. 그렇지 않은 경우, 현재 세션 타임존이 사용됩니다.반환 값은 항상 TIMESTAMP_TZ 형식입니다.
For
source_tz
andtarget_tz
, you can specify a time zone name or a link name from release 2021a of the IANA Time Zone Database (e.g.America/Los_Angeles
,Europe/London
,UTC
,Etc/GMT
, etc.).참고
Time zone names are case-sensitive and must be enclosed in single quotes (e.g.
'UTC'
).Snowflake does not support the majority of timezone abbreviations (e.g.
PDT
,EST
, etc.) because a given abbreviation might refer to one of several different time zones. For example,CST
might refer to Central Standard Time in North America (UTC-6), Cuba Standard Time (UTC-5), and China Standard Time (UTC+8).
예¶
ALTER SESSION SET timestamp_output_format = 'YYYY-MM-DD HH24:MI:SS';
-- Convert a "wallclock" time in Los Angeles to the matching "wallclock" time in New York
SELECT CONVERT_TIMEZONE('America/Los_Angeles', 'America/New_York', '2019-01-01 14:00:00'::timestamp_ntz) AS conv;
+-------------------------+
| CONV |
|-------------------------|
| 2019-01-01 17:00:00.000 |
+-------------------------+
-- Convert a "wallclock" time in Warsaw to the matching "wallclock" time in UTC
SELECT CONVERT_TIMEZONE('Europe/Warsaw', 'UTC', '2019-01-01 00:00:00'::timestamp_ntz) AS conv;
+-------------------------+
| CONV |
|-------------------------|
| 2018-12-31 23:00:00.000 |
+-------------------------+
ALTER SESSION UNSET timestamp_output_format;
-- Convert TIMESTAMP_TZ to a different time zone and include the time zone in the result
SELECT CONVERT_TIMEZONE('America/Los_Angeles', '2018-04-05 12:00:00 +02:00') AS time_in_la;
+-------------------------------+
| TIME_IN_LA |
|-------------------------------|
| 2018-04-05 03:00:00.000 -0700 |
+-------------------------------+
ALTER SESSION UNSET timestamp_output_format;
-- Show the current "wallclock" time in different time zones
SELECT
CURRENT_TIMESTAMP() AS now_in_la,
CONVERT_TIMEZONE('America/New_York', CURRENT_TIMESTAMP()) AS now_in_nyc,
CONVERT_TIMEZONE('Europe/Paris', CURRENT_TIMESTAMP()) AS now_in_paris,
CONVERT_TIMEZONE('Asia/Tokyo', CURRENT_TIMESTAMP()) AS now_in_tokyo;
+-------------------------------+-------------------------------+-------------------------------+-------------------------------+
| NOW_IN_LA | NOW_IN_NYC | NOW_IN_PARIS | NOW_IN_TOKYO |
|-------------------------------+-------------------------------+-------------------------------+-------------------------------|
| 2019-01-11 14:23:08.497 -0800 | 2019-01-11 17:23:08.497 -0500 | 2019-01-11 23:23:08.497 +0100 | 2019-01-12 07:23:08.497 +0900 |
+-------------------------------+-------------------------------+-------------------------------+-------------------------------+