postgresql 获取两个时间类型小时差值案例
时间:2021-04-13 09:13:10|栏目:PostgreSQL|点击: 次
我就废话不多说了,看代码吧~
select extract(day from t) * 24 + extract(hour from t) from (select (timestamp '2013-12-14 12:00:00' - timestamp '2013-12-11 4:00:00') as t) as a;
例如a表中有start,end俩字段
select extract(day from (end-start)) * 24 + extract(hour from (end-start)) from a
补充:PostgreSQL得出两个timestamp的秒数差值
sql语句
SELECT EXTRACT(EPOCH FROM (TIMESTAMP '2017-12-16 12:21:13'- TIMESTAMP '2017-12-15 12:21:00'));
86413
计算两个时间的差值更新另一个时间字段
UPDATE your_table
SET this_time=(EXTRACT(EPOCH FROM (time_a-time_b)));