datetime in 4GL
Posted in 1995
> > Greetings fellow Informix 4GLer's: > > I have a question/obersevation converning using datetime in Informix > 4GL. Informix 4.11 running under SCO to be exact. Consider the > following stub code: > > main > define dt1, dt2, dt3, > time_tot decimal(6,2), > mins decimal(6,2) > > let dt1 = current > let time_tot = 6.5 > let mins = 6.5 * 60 > let dt2 = dt1 + time_tot units hour # add the hours > let dt3 = dt1 + mins units minute # add the minutes > end main > > You would think both dt2 and dt3 would be the same answer, but the > hours datetime calculation dt2, drops the decimal part of the hour. > The minutes calculation, dt3, is correct. > > This isn't a real "show stopper", but am I missing something here? > > Please advise, > > > ed > schaefer The following is the results of this code. I added a display var_name, var after each assignment statement. FORMS statement error number -1260. It is not possible to convert between the specified types. # trying to put a datetime into a decimal dt1 time_tot 6.50 # no prob mins 390.00 # no prob dt2 # dt1 is hosed, so can't do this. dt3 # dt1 is hosed, so can't do this. ----- I then changed dt1, dt2, dt3 to be DATETIME HOUR TO MINUTE: dt1 09:25 # now. time_tot 6.50 # 6.5 mins 390.00 # 6.5 * 60 dt2 15:25 # dt3 15:55 # Now we see your problem. I would guess that you can't have a 6.5 units hour. ===> LET dt2 = dt2 + .5 units hour DISPLAY "dt2", dt2 yields 15:25 same as before. What I suggest is that you don't try to date (essentially) arithmetic with decimal fields. Use DATETIME and/or INTERVAL like they are supposed to be used. In past experiments I have also noted that it is not wise to combine multiple operations on one line. I did a write up on Interval/datetime operations that is included in the FAQ. While it deals with a specific situation, it does explore this world. cheers j. _____________________________________________________________________________ Jack Parker - Hewlett Packard, BSMC Boise, Idaho, USA jparker@hpbs3645.boi.hp.com _____________________________________________________________________________ Back up my hard drive? You mean these things can actually run in reverse? _____________________________________________________________________________ Any opinions expressed herein are my own and not those of my employers. _____________________________________________________________________________