Snowflake’s built-in way to get the current timezone is using the SHOW statement, like this:
show parameters like 'TIMEZONE';
If you’re running the statement from a command line, this isn’t a problem. If you need it programmatically, the SHOW command has two key limitations. First, you can’t use it in a stored procedure. Second, if you use it in a SQL script running externally, you have to get the results of the SHOW statement in second query using RESULT_SCAN.
One of my customers needed a way to get and current timezone in a single call and use it in a stored procedure. Since JavaScript has built-in functions, it’s possible to use a UDF to get the current time zone that way:
create or replace function GET_CURRENT_TIMEZONE()
returns string
language javascript
as
$$
return Intl.DateTimeFormat().resolvedOptions().timeZone;
$$;
-- Test the UDF:
select get_current_timezone();
alter session set TIMEZONE = 'America/Chicago';
select get_current_timezone();
alter session set TIMEZONE = 'America/New_York';
select get_current_timezone();