Bul*_*ush 2 postgresql datetime date postgresql-9.1
Postgresql 9.1
我正在尝试使用查询来查找时间表系统的2个日期和2个时间之间的小数/小数小时差异.我正在使用查询来确保软件(不是我编写的)没有任何错误.以下是我正在使用的表中的字段:startdate是Date字段,starttime是Time字段,enddate是Date字段,endtime是Time字段.
示例数据:
我也试过这个sql语句.
SELECT employeetime.dcmasterid as empid,
nonchargeabletime.startdate as ncsdate,
nonchargeabletime.starttime as ncstime,
nonchargeabletime.enddate as ncedate,
nonchargeabletime.endtime as ncetime,
employeetime.dchours as normhrs,
(timestamp (startdate || ' ' || starttime) - timestamp (enddate || ' ' || endtime)) as diffhrs
FROM employeetime, nonchargeabletime
WHERE (nonchargeabletime.employeetime=employeetime.dcautoinc)
AND (nonchargeabletime.startdate >= '2016-04-24')
AND (nonchargeabletime.startdate <= '2016-04-30')
AND (employeetime.dcmasterid IN ('BLURG'))
AND (nonchargeabletime.nonchargeabletype=10)
ORDER BY employeetime.dcmasterid, nonchargeabletime.startdate, nonchargeabletime.starttime;
Run Code Online (Sandbox Code Playgroud)
但是我startdate说它的语法错误(timestamp (startdate ||.
任何人有任何线索如何做到这一点?
谢谢.
添加time到date收益率timestamp减去从另一个回报的一个时间戳interval.
所以你需要做的就是:
(enddate + endtime) - (startdate + starttime) as diff
Run Code Online (Sandbox Code Playgroud)
一个interval是SQL的情况下很好的,但通常很难在编程语言来处理.您可以轻松地使用转换interval为秒extract(epoch from interval)
如果你想将它转换为小时使用extract并除以3600
extract(epoch from (enddate + endtime) - (startdate + starttime))/3600 as diff_hours
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5245 次 |
| 最近记录: |