Preform math calculation upon dates [message #493624] |
Wed, 09 February 2011 02:29 |
Sarlula
Messages: 18 Registered: September 2010
|
Junior Member |
|
|
I got 4 fields:
event_date (01/01/1900 hh:mm:ss)
team_count (number)
interview_count (number)
duration (01/01/1900 hh:mm:ss) - duration of each interview
The calculation is:
(interview_count * team_count * duration(hh:mm)) + event_date
i.e.:
(3 * 2 * 02:30) + 01/01/1900 08:00:00
= 15:00:00 + 01/01/1900 08:00:00
= 01/01/1900 23:00:00.
all I care about is the hh:mm in the result.
How can I preform this calculation in pl/sql?
I tried all possible ways I could think of..
|
|
|
|
|
|
Re: Preform math calculation upon dates [message #493648 is a reply to message #493639] |
Wed, 09 February 2011 04:04 |
Sarlula
Messages: 18 Registered: September 2010
|
Junior Member |
|
|
The duration is a date (its an old DB).
the test-code is:
create table testme
(
event_date DATE,
team_count NUMBER,
interview_count NUMBER,
duration DATE
);
insert into testme (event_date, team_count, interview_count, duration)
VALUES ('01-jan-1900 08:00:00', 2, 3, '01-jan-1900 02:30:00');
select extract(hour FROM
to_timestamp(to_char(to_date(
(
(e.duration * e.team_count * e.summonscount) + e.event_date),
'dd-mon-yyyy HH24:MI:SS'),
'dd-mon-yyyy HH24:MI:SS')))
from testme;
I want the output to be: 23.
|
|
|
Re: Preform math calculation upon dates [message #493651 is a reply to message #493648] |
Wed, 09 February 2011 04:18 |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
If you subtract two dates you get the difference in days. When you multiply that difference in days with 24 you get the difference in hours.
Example:
SELECT (duration - Trunc(duration)) * 24,
(event_date - Trunc(event_date)) * 24
FROM testme
Then you can multiply/add those numbers at will.
|
|
|
Re: Preform math calculation upon dates [message #493652 is a reply to message #493648] |
Wed, 09 February 2011 04:23 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
SQL> select event_date +
2 (team_count * interview_count * to_number(to_char(duration,'SSSSS')))
3 / 86400
4 from testme
5 /
EVENT_DATE+(TEAM_COU
--------------------
01-jan-1900 23:00:00
Regards
Michel
|
|
|
|