函数date_part,获取日期相差天数

使用date_part函数

 -- create_time 2022-06-09 17:06:20  now()  2022-06-08 09:03:00
 select date_part('day',cast(su.create_time as TIMESTAMP)-cast(now() as TIMESTAMP)) from face_data as su where id=300124

在这里插入图片描述

获取当日期2022-06-08和2022-06-01相差天数

	select CURRENT_DATE::date - '2022-06-01'::date;

函数date_part,获取日期相差天数_第1张图片
处理秒

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);
 

你可能感兴趣的:(java,postgresql,postgresql)