For the hours I use it as date data type. When I subtract it, it just normally deducts. How can I subtract it in time format like hours? I tried put datediff, timestampdiff, but it says invalid identifier. Must I create any function before executing? Or did I not activate datediff on Oracle?
Below is my code:
Select S.Test_Date, E.Testno, S.Examno, S.Serialno, 'Science'
,DATEDIFF(hours, F.STARTED, F.ENDED) as hours From Semester S, TIME F
,TESTPAPERS e
Where S.Testno= F.Testno
And E.Testno =1;
For timestampdiff:
Insert Into Test (Test_Date, Testno, Examno, Serialno, Type, Hours)
Select S.Test_Date, E.Testno, S.Examno, S.Serialno, 'Science'
, TIMESTAMPDIFF(F.STARTED- F.ENDED) as hours From Semester S, TIME F
, TESTPAPERS e
Where S.Testno= F.Testno
And E.Testno =1;
In Oracle, you can do arithmetic on date/time expressions easily. Subtracting one expression from another yields the number of days (with floating-point precision) between the two expressions.
For example,
sysdateis right now,sysdate-1is exactly one day ago,sysdate-(1/24)is one hour ago, and so forth.So if you have two date/time items named
whenandthen, the number of hours between them is(when-then)*24No need to make it more complex than that if you’re staying in Oracle. You don’t need datediff, which is good because it isn’t there.