简体   繁体   中英

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.

I already tried using DATADIFF and simple subtraction converting the field to just time.

  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. 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. To get the difference in minutes, you can multiply the result by 24 (hours per days) and 60 (minutes per hour):

(Fim_Hora - Inicio_Hora) * 24 * 60 diff_minutes

This assumes that both Fim_Hora and Inicio_Hora are of datatype DATE .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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