How can I get the current Unix epoch timestamp in Snowflake? I could not find any documentation on the same
How can I get the current Unix epoch timestamp in Snowflake? I could not find any documentation on the same
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
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).