Re: DATETIME/INTERVAL Conversions
Posted in 1993
In article <1993Apr5.195003.11135@b8.b8.ingr.com> jdryburn@smt_6.b21.ingr.com (Joe Ryburn) writes: >I have an application storing time values as DATETIME YEAR TO MINUTE values. >I need to calculate a fraction, or percentage that a sum of minutes is >relative to a total INTERVAL. Each value, that is the total minutes and >the partial minutes used as denominator and numerator of the fraction, is >an INTERVAL value calculated from the DATETIME entries. Is there a way to >calculate percentages from these two values? Normal INTERVAL division >is integer type math, in that a smaller INTERVAL divided by a larger >INTERVAL always returns zero. I am using I4GL 4.1 for the program. It shouldn't return zero, it should return an error. You can only divide/multiply intervals by integers. >Any help would be appreciated! >Joe Ryburn | CIM Manager | Intergraph Corporation Not to worry. Just convert all figures into the smallest unit of precision (e.g. minutes), then convert to integers and use regular math. You can't convert directly from interval to integer, so convert to character in-between. The following example should get you started: main define i0 interval day to minute define i1 interval minute(4) to minute define i2 interval minute(4) to minute define c1 char(10) define c2 char(10) define n1 integer define n2 integer define quo1 decimal(12,4) define quo2 decimal(12,4) let i0 = "0 12:12" -- 0 days, 12 hours, 12 minutes let i1 = i0 let i2 = "12" display "int1 = ", i1, " int2 = ", i2 let c1 = i1 let n1 = c1 display "n1 = ", n1 let c2 = i2 let n2 = c2 display "n2 = ", n2 let quo1 = n1 / n2 let quo2 = n2 / n1 display "quo1 = ", quo1, " quo2 = ", quo2 end main