Mithun Manohar
Mithun Manohar

Reputation: 586

Snowflake: how to get the current Unix epoch timestamp

How can I get the current Unix epoch timestamp in Snowflake? I could not find any documentation on the same

Upvotes: 9

Views: 21577

Answers (2)

Lukasz Szozda
Lukasz Szozda

Reputation: 175586

Using DATEDIFF:

SELECT DATEDIFF(second, '1970-01-01'::DATE, CURRENT_TIMESTAMP());

or DATE_PART:

SELECT DATE_PART(epoch_second, CURRENT_TIMESTAMP());

Supported Date and Time Parts:

epoch_second

epoch_millisecond

epoch_microsecond

epoch_nanosecond

Upvotes: 18

Felipe Hoffa
Felipe Hoffa

Reputation: 59165

This solution is timezone independent, no math needed:

alter session set timezone = 'US/Eastern';
select date_part(epoch_second, current_timestamp());
-- 1637194610

alter session set timezone = 'America/Los_Angeles';
select date_part(epoch_second, current_timestamp());
-- 1637194621

Note that current_timestamp() returns what you want, while current_date() only returns the day (without a time component).

Upvotes: 6

Related Questions