postgresql 计算时间差的秒数、天数

处理时间时用到了,记录一下。

时间差天数

select '2017-12-10'::date - '2017-11-01'::date;

时间差秒数

select extract(epoch FROM (now() - (now()-interval '1 day') ));

select trunc(extract(epoch FROM (now() - (now()-interval '1 day') ))::numeric);

select trunc(extract(epoch FROM (now() - (now()-interval '1 day') ))::numeric,1);

select round(extract(epoch FROM (now() - (now()-interval '1 day') ))::numeric);

select round(extract(epoch FROM (now() - (now()-interval '1 day') ))::numeric,1);