postgresql 计算时间差的秒数、天数实例
时间:2021-04-15 11:19:06|栏目:PostgreSQL|点击: 次
处理时间时用到了,记录一下。
时间差天数
select '2017-12-10'::date - '2017-12-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);
补充:postgresql计算2个日期之间工作日天数的方法
select date_part( 'day', minus_weekend(begin_date,end_date)) from table1 where name in ('a', 'b', 'c')