Asynchronousx
Asynchronousx

Reputation: 101

Select an hour interval between two date SQL Oracle 11g

I'm writing a trigger for an online videogame project for my university, and this trigger was intended for putting an advertising after 8 hours of game (with a DBMS Output on the trigger I guess).

But i'm having trouble calculate this difference :

For example, I got :

LOGINDATE              LOGOUTDATE
--------------------   --------------------
15-MAG-2017 23:15:42   16-MAG-2017 02:15:54

In the trigger I would like to take the total amount of hours subtracting it from LOGINDATE-LOGOUTDATE, and saving that into a variabile MAX_HOURS that will do the trick into an IF STATEMENT ( IF MAX_HOURS > 8, for example )

Is there some way to do this ?

Upvotes: 0

Views: 70

Answers (1)

OldProgrammer
OldProgrammer

Reputation: 12179

Example:

select (LOGOUTDATE - LOGINDATE)*24 
INTO MAX_HOURS 
        from your_table;

result of date subtraction is in units of days. Multiply to 24 hours to get units of hours.

Upvotes: 2

Related Questions