Re: Converting INTERVAL to integer minutes?
Posted in 1998
Thomas J. Girsch wrote:
> You could try looking up EXTEND in the manuals. It should be in
> the syntax guide under "expression."
Unfortunately, EXTEND applies to DATETIME and not to INTERVAL.
> David C Mudie wrote in message ...
> >Hi, I'm new to Informix and to this newsgroup. I am using Informix
> >Developer's Edition v7.20.UC4 on Solaris 2.6. I have a field of
> >type INTERVAL DAY TO MINUTE and I would like to convert it to
> >an integer count of minutes. Is there some built-in conversion
> >function I can use for this, or do I have to write my own stored
> >procedure or host-language routine?
You can do it with either SPL or in ESQL/C, but you should also
consider DejaNews as a resource. As a newcomer, you wouldn't know
to include my name in the search, but when I power-searched DejaNews
for articles I posted in c.d.i with INTERVAL in the subject since the
beginning of 1997, there is a 5-part article from May 1997 (one posting
split into 5 pieces) which has a SPL solution for handling hours;
doing minutes is fairly simple. It also has some ESQL/C code which
returns the value of an interval as a DECIMAL (with fractions); you
can truncate that result to get the integer value.
-- Untested code. The variable s is necessary; so is n.
CREATE PROCEDURE ivdaymin_min(ivdm INTERVAL DAY TO MINUTE)
RETURNING INTEGER; DEFINE n INTERVAL MINUTE(9) TO MINUTE;
DEFINE s CHAR(12);
LET n = ivdm - 0 UNITS MINUTE;
LET s = n;
RETURN s;
END PROCEDURE;
> >I haven't been able to find any answers in the Informix docs or FAQ,
> >and my version of "dbaccess" doesn't seem to recognize the CAST
> >operator defined in SQL-92. Any pointers appreciated, thanks!
Certainly CAST is not in 7.2x; it is probably in the 9.x family and
might be in the 7.3x family.
--
Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net)
Guardian of DBD::Informix v0.60 -- see http://www.perl.com/CPAN
#include <disclaimer.h>