我已经有一段时间没发了。我有个关于日期计算的问题。
我试图找出两个日期之间的区别,如在开始时间和结束时间。
我已经找到了不同的日子,因此,例如,如果我有日期:
start = 12/11/2014 12:05:05
finish = 13/11/2014 09:44:19然后查询给我-0.90224537.
然而,我需要以小时、分钟、秒的形式回答工资问题。做这件事最好的方法是什么?
到目前为止我的疑问是:
select
time_sheet.time_sheet_id,
time_sheet.start_date_time - time_sheet.finish_date_time,
employee_case.case, employee_case.employee
from
time_sheet
inner join
employee_case on time_sheet.employee_case = employee_case.employee_case_id
where
employee_case.case = 1;我正在使用Oracle数据库:)
发布于 2014-11-29 14:59:46
date - date产生days的差异。因此,您可以使用标准时间转换将其转换为小时、分钟和秒,如下所示:
select
time_sheet.time_sheet_id,
(time_sheet.finish_date_time - time_sheet.start_date_time)||' days'||(time_sheet.finish_date_time - time_sheet.start_date_time)*24||' hours '||(time_sheet.finish_date_time - time_sheet.start_date_time)*24*60||' minutes '||(time_sheet.finish_date_time - time_sheet.start_date_time)*24*60*60||' seconds ' ,
employee_case.case, employee_case.employee
from
time_sheet
inner join
employee_case on time_sheet.employee_case = employee_case.employee_case_id
where
employee_case.case = 1;此外,为了避免负值,您还需要finish_date_time作为分钟,start_date_time作为减法。
发布于 2014-11-29 15:41:56
谢谢帮助蹒跚学步的孩子,但我决定走另一条路。对于其他有同样问题的人,我做了以下工作:
select
time_sheet.time_sheet_id,
to_number( to_char(to_date('1','J') +
(time_sheet.finish_date_time - time_sheet.start_date_time), 'J') - 1) days,
to_char(to_date('00:00:00','HH24:MI:SS') +
(time_sheet.finish_date_time - time_sheet.start_date_time), 'HH24:MI:SS') time,
employee_case.case, employee_case.employee
from
time_sheet
inner join
employee_case on time_sheet.employee_case = employee_case.employee_case_id
where
employee_case.case = 1;这似乎正是我所需要的。它会把时间、时间、分、秒都用在一条蛇的地里,但就我而言,这是可以接受的。
https://stackoverflow.com/questions/27203521
复制相似问题