Openedge syntax for TIME minus 4 hours

1.6k Views Asked by At

I am trying to figure out how to write a Openedge query where i can look back 4 hours. i have struggled with the TIME syntax before. If i understand correctly, the TIME representation in Openedge is in seconds starting from midnight. The query i am trying to write would run 4 times a day, looking back 4 hours.

Is there any way to do this using TIME? Maybe i have to write 4 different queries that only pull records starting at a specific time?

Thanks very much for any help i can get, it is greatly appreciated!

Martin

1

There are 1 best solutions below

0
On

You don't describe the contents or layout of the table very well.

Yes, TIME, in Progress ABL contains the number of seconds since midnight. So 16:20 for instance is 58800 (16 * 3600 + 20 * 60).

Assuming the field in your table contains an integer representing the time you can do like this to select the records that was created up to four hours ago:

DEFINE VARIABLE iTime AS INTEGER     NO-UNDO.
/* I find it easier to write like this but you can very well do = TIME - 14400 instead */
iTime = TIME - 4 * 3600.

FOR EACH tablename NO-LOCK WHERE tablename.createtime >= iTime:
  /* Do something */
END.

Note: perhaps you need to check create date as well? And handle midnight?

Another option might be to look at the DATETIME type. There you can do operations like adding and distracting an amount of time.

DEFINE VARIABLE datnow  AS DATETIME    NO-UNDO.
DEFINE VARIABLE datthen AS DATETIME    NO-UNDO.

datnow = NOW.

DISPLAY datnow.

datthen = ADD-INTERVAL(datnow, -4, "hours").

DISPLAY datthen.