There isn't an easy, direct way to do it -- there should be, but there
isn't. Extracting components into a datetime isn't too hard (or too easy):
LET day_part = EXTEND(usage, DAY TO DAY)
LET hour_part = EXTEND(usage, HOUR TO HOUR)
etc.
That assumes that day_part is declared as INTERVAL DAY TO DAY. However,
you can also use the CHAR type -- which is necessary to get to INTEGER, as
you then assign the CHAR value to the INTEGER value. So, the following
code will work:
DEFINE
usage INTERVAL DAY TO SECOND,
tmp CHAR(10),
days INTEGER,
hours INTEGER,
minutes INTEGER,
seconds INTEGER
LET usage = INTERVAL(23 22:21:20) DAY TO SECOND
LET tmp = EXTEND(usage, DAY TO DAY)
LET days = tmp
LET tmp = EXTEND(usage, HOUR TO HOUR)
LET hours = tmp
LET tmp = EXTEND(usage, MINUTE TO MINUTE)
LET minutes = tmp
LET tmp = EXTEND(usage, SECOND TO SECOND)
LET seconds = tmp
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>
>From: Hoang Nguyen <harryn@cerf.net>
>Date: Thu, 7 Mar 1996 12:26:35 -0800
>X-Informix-List-Id: <news.21864>
>
>I have a question regarding converting interval values into day, hour,
>minute, second variables, I hope someone can help:
>
>For example, the interval value is defined as :
>
>DEFINE
> usage INTERVAL DAY TO SECOND
>
>and in my 4gl program, I have a value "1 02:30:45" for usage variable.
>now, I want to break down this interval so that I can have one of
>the following variables:
>
>day = 1 (integer)
>hour = 2 (integer)
>minure = 30 (integer)
>second = 45 (integer)
>
>and I want to uses these variable (day, hour...) to do some
>futher calculations