Re: Datetime/Interval Question
Posted in 2004
Jonathan Leffler <jleffler@earthlink.net> wrote: >> The UNITS keyword doesn't seem to exist in ESQL/C. When I use the >> "dtaddinv()" function, do I really first have to convert the >> minutes into an interval hour to minute variable (or in case >> there are more than 1440 minutes, an interval day to minute >> variable) and then apply that function, or is there an easier >> method to accomplish this? >> >> Maybe someone has a ready-to-use function to convert a number >> of minutes into a suitable interval variable? > >Yes, you do have to create an interval type to deal with it. > >You would normally use an INTERVAL MINUTE(9) TO MINUTE variable for >the number of minutes - so you don't have to convert more than 60 >minutes into hours and minutes, or more than 1440 minutes into days, >hours and minutes. Thanks, also to Art S. Kagel for his helpful mail. As it turned out, an INTERVAL MINUTE(4) TO MINUTE worked beautifully. It's a bit awkward that there is no direct conversion function available between "int" and "interval", I have to convert the "int" to a string using "sprintf" and then use the "incvasc()" function to get the interval, but that is just a little nuisance. >I don't have the function pre-coded. At the IIUG, there is code in >intvl_conv that is the closest shot - it converts incoming intervals >into total number of seconds, or total number of minutes, or whatever, >as a decimal number with a fractional part too. Thanks for your code examples. The above was totally sufficient, all I wanted was having to convert a number of minutes into days, hours and minutes. I had misinterpreted the code example for the incvasc() function in the ESQL/C manual. Regards, Richard