当前位置:   article > 正文

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

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
  • 1
  • 2

在这里插入图片描述

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

	select CURRENT_DATE::date - '2022-06-01'::date;
  • 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);
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/577200
推荐阅读
相关标签
  

闽ICP备14008679号