Reputation: 17
I need to calculate difference of two dates in Oracle. It's not a problem, but there is a condition. I made a timestamp when the task was created and then new timestamp when the task was finished. And I need to calculate the difference, but:
When the task was created and finished in the same day I need to get the difference = 1 (because they were working on it for one day) and when the task was started yesterday and finished today I need the difference = 2. I hope you understand, if not ask me for more information.
Upvotes: 0
Views: 508
Reputation: 50017
I'll assume here that your dates are held in columns of type DATE. If so, the following should do what you want:
SELECT TRUNC(END_DATE) - TRUNC(START_DATE) + 1 AS ELAPSED_DAYS
FROM A_TABLE
Share and enjoy.
Upvotes: 2
Reputation: 31627
select MOD(24 * (to_date('2009-07-08 23:00', 'YYYY-MM-DD hh24:mi')
- to_date('2009-07-07 22:00', 'YYYY-MM-DD hh24:mi')), 24)+1 diff_days
from dual;
Upvotes: 0