Skip to content
Advertisement

How to calculate total time from date column in Oracle

I have a table where i have some log like this.

and output is like below

But I want to have one more column which will give me total time like below

I have tried to minus both time but not getting proper result.

The output i am getting is below

Advertisement

Answer

Don’t convert the dates to strings. That makes no sense and only leads to unexpected results. The column dato is a DATE and per table you want the minimum dato and the maximum dato, so just use MIN(dato) and MAX(dato). Then you want the difference. You get the difference by subtracting one from the other:

As dato is a DATE, you get the difference as a fraction of days. If you want an INTERVAL instead, convert from DATE to TIMESTAMP:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement