UNIXタイムと時刻の変換

(8.0.22)
https://qiita.com/reneice/items/b385e143fcbb144f4f3e


-- 時刻→UNIXタイム
select unix_timestamp('2021-09-19 12:34:56');
select unix_timestamp(now());

-- UNIXタイム→時刻

select from_unixtime(1632036429);

 

(19c)
http://kazemati.blogspot.com/2011/05/oracle-sqldateunix.html


-- 時刻→UNIXタイム

select to_number(to_date('2021/09/19 12:34:56', 'YYYY/MM/DD HH24:MI:SS') - to_date('1970/01/01 00:00:00', 'YYYY/MM/DD HH24:MI:SS')) * (24 * 60 * 60) unixtime from dual;
select to_number(sysdate - to_date('1970/01/01 00:00:00', 'YYYY/MM/DD HH24:MI:SS')) * (24 * 60 * 60) unixtime from dual;


-- UNIXタイム→時刻
alter session set nls_date_format='YYYY/MM/DD HH24:MI:SS';

select to_date('1970/01/01 00:00:00', 'YYYY/MM/DD HH24:MI:SS')+ 1632068860 / (24 * 60 * 60) mytime from dual;

 

(13)
https://litt.hatenadiary.org/entry/20070904/p1


-- 時刻→UNIXタイム
select extract(epoch from timestamp with time zone '2021-09-19 12:34:56');
select extract(epoch from date_trunc('second',clock_timestamp()));

 

-- UNIXタイム→時刻
select to_timestamp(1632036478);

 

(2019)
https://qiita.com/analytics-hiro/items/25f311ff7dab6d2c8fbd


-- 時刻→UNIXタイム
select datediff(s,'1970/1/1', '2021-09-19 12:34:56');
select datediff(s,'1970/1/1', getdate());

 

-- UNIXタイム→時刻
select dateadd(s,1632069131, '1970/1/1');