简体   繁体   English

sql Oracle 的时差

[英]time difference in sql Oracle

I need to know a difference between start time and end time.我需要知道开始时间和结束时间之间的区别。 Both are DATETIME fields, I tried to use "-" and DATADIFF.两者都是 DATETIME 字段,我尝试使用“-”和 DATADIFF。

I already tried using DATADIFF and simple subtraction converting the field to just time.我已经尝试使用 DATADIFF 和简单的减法将字段转换为时间。

  1. (to_date(Fim_Hora,'HH24:MI') - to_date(Inicio_Hora,'HH24:MI')) AS Diferenca

  2. DATADIFF(MIN,Fim_Hora,Inicio_Hora)

I need to know the time in minutes for use as parameters.我需要知道用作参数的时间(以分钟为单位)。

Oracle does not have a time data type. Oracle 没有time数据类型。 Usually, subtraction works well enough:通常,减法效果很好:

select (end_time - start_time) as diff

You may need to convert to a string if you want it formatted in a particular way.如果您希望它以特定方式格式化,您可能需要转换为字符串。

In Oracle, you can directly substract dates, it returns the difference between the dates in days.在 Oracle 中,您可以直接减去日期,它以天为单位返回日期之间的差异。 To get the difference in minutes, you can multiply the result by 24 (hours per days) and 60 (minutes per hour):要获得以分钟为单位的差异,您可以将结果乘以 24(每天的小时数)和 60(每小时的分钟数):

(Fim_Hora - Inicio_Hora) * 24 * 60 diff_minutes

This assumes that both Fim_Hora and Inicio_Hora are of datatype DATE .这假设Fim_HoraInicio_Hora都是数据类型DATE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM