Number of hours from interval, how?
Posted in 1997
Topics: Stored Procedures & SPL
Hello,
maybe the following is a FAQ, but I couldn't find something
about it in that document, so here goes:
Summary:
How do I get the number of hours from a datetime
difference (an interval) as integer value?
Longer Explanation:
Example Table:
CREATE TABLE mytable (
mykey CHAR(10),
mydatetime DATETIME YEAR TO FRACTION(3)
);
The value of mydatetime is somewhere in the future.
I want to compute the number of hours this point of time
is away from now.
I can do something like
SELECT EXTEND (mydatetime, YEAR TO HOUR) - CURRENT YEAR TO HOUR
FROM mytable
WHERE mykey = 'ABC';
This gives an INTERVAL DAY TO HOUR(?) value of let's
say '10 13', saying the difference is ten days and 13 hours.
That is the 'nearest' I could get so far.
But I wish to have the number of hours (in this example 253).
How To?
The value is needed for further computing in a
function that computes kind of a 'most urgent' entry.
A computation like
<constant weight factor> * <number of hours left>
is part of this function (amongst others).
I like to create a view which has a column
that gives me this number of hours as an integer value.
I also tried writing a SPL-Procedure to fill this column but
with no success.
Engine is SE 7.22.
Any help is appreciated.
Gottfried.
--
Gottfried Schwieters **
Quantum GmbH **
44137 Dortmund **