How to Convert Timezone in Snowflake

Galaxy Glossary

How do I convert timestamps between time zones in Snowflake?

CONVERT_TIMEZONE shifts a timestamp from one time zone to another in Snowflake.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Why convert time zones in Snowflake?

Analytics often require aligning timestamps to a businessa0timea0zone. Using CONVERT_TIMEZONE lets you present dates in a usera0friendly zone without altering stored values.

What is the basic CONVERT_TIMEZONE syntax?

Use three arguments: source zone, target zone, and timestamp. When the sessiona0timea0zone is the source, supply only target zone and timestamp.

How do I convert order timestamps to UTC?

Wrap the order_date column in CONVERT_TIMEZONE('America/Los_Angeles', 'UTC', order_date). The result is a TIMESTAMP_TZ in UTC.

Can I store converted values?

Yes. Use CREATE TABLE AS or UPDATE to persist the converted column, ensuring downstream queries always reference the correct zone.

What happens with daylight saving?

Snowflake applies IANA rules automatically. CONVERT_TIMEZONE adjusts for DST, so 2024-03-10 02:30 PST becomes 10:30 UTC.

Is casting required?

No. However, casting to TIMESTAMP_TZ can avoid ambiguity. Use order_date::timestamp_tz before conversion when data type is string.

How to audit conversions?

Add both local and UTC columns in SELECTs. Developers can verify values side-by-side during migration.

Why How to Convert Timezone in Snowflake is important

How to Convert Timezone in Snowflake Example Usage


-- Show each order time in both the customera0zone and UTC
SELECT 
    o.id,
    c.name,
    CONVERT_TIMEZONE('UTC', 'America/New_York', o.order_date)        AS order_date_est,
    CONVERT_TIMEZONE('UTC', 'Europe/London',     o.order_date)        AS order_date_gmt
FROM Orders o
JOIN Customers c ON c.id = o.customer_id
WHERE o.order_date >= DATEADD(day,-7,CURRENT_TIMESTAMP());

How to Convert Timezone in Snowflake Syntax


CONVERT_TIMEZONE(
    <source_tz> VARCHAR,
    <target_tz> VARCHAR,
    <timestamp> TIMESTAMP_LTZ | TIMESTAMP_NTZ | TIMESTAMP_TZ
)

-- Two-argument form (session time zone assumed as source)
CONVERT_TIMEZONE(
    <target_tz> VARCHAR,
    <timestamp> TIMESTAMP_LTZ | TIMESTAMP_NTZ | TIMESTAMP_TZ
)

-- Example with ecommerce data
SELECT 
    id,
    order_date,
    CONVERT_TIMEZONE('America/New_York','UTC', order_date) AS order_date_utc
FROM Orders;

Common Mistakes

Frequently Asked Questions (FAQs)

Does CONVERT_TIMEZONE work with TIMESTAMP_NTZ?

Yes. Snowflake treats NTZ as seconds from epoch. It assumes the value is in the session time zone when converting.

Can I change my session time zone instead?

Yes. Execute ALTER SESSION SET TIMEZONE = 'America/New_York';. All TIMESTAMP_TZ outputs will then render in that zone without changing storage.

Is performance impacted?

The function is deterministic and operates in-memory. Over millions of rows the cost is minimal compared to network I/O.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.