Varun K S
Varun K S

Reputation: 77

Time Function in Progress 4GL

I would like to insert 2 shift timings to the code.

  1. (First Shift) Shift starts from 8:00:00:000 to 19:59:59:999
  2. (Second Shift) Shift Starts from 20:00:00:000 to next day 7:59:59:999

I need to get the above exact data to be added to the below code. Please help. Below is the code:

IF TIME < (20 * 60 * 60)  THEN  DO: 
     ASSIGN StartDDT = dt_tm2dec(DATE(TODAY), 0)
            EndDDT   = dt_tm2dec(DATE(TODAY),19 * 60 * 60 + 59 * 60 + 59).
END.
ELSE DO: 
    ASSIGN StartDDT = dt_tm2dec(DATE(TODAY),20 * 60 * 60).
            EndDDT  = dt_tm2dec(DATE(TODAY + 1),07 * 60 * 60 + 59 * 60 + 59).
END.

Upvotes: 0

Views: 1605

Answers (2)

TheDrooper
TheDrooper

Reputation: 1217

You can use the DATETIME datatype to get millisecond accuracy on your times. Build the shift times with the DATETIME function, then compare your time to them. The NOW function gives you the current time down to the millisecond:

DEFINE VARIABLE dtShift1 AS DATETIME NO-UNDO.
DEFINE VARIABLE dtShift2 AS DATETIME NO-UNDO.

ASSIGN
    dtShift1 = DATETIME(TODAY, (8 * 60 * 60 * 1000))
    dtShift2 = DATETIME(TODAY, (20 * 60 * 60 * 1000)).

IF NOW >= dtShift1 AND NOW < dtShift2 THEN
    MESSAGE "First shift" VIEW-AS ALERT-BOX INFORMATION.
ELSE
    MESSAGE "Second shift" VIEW-AS ALERT-BOX INFORMATION.

You can also check the shift time for the following day by adding a day to TODAY:

dtShift1 = DATETIME(TODAY + 1, (8 * 60 * 60 * 1000))

And if you need to handle different time zones, use the DATETIME-TZ datatype.

Upvotes: 1

Tom Bascom
Tom Bascom

Reputation: 14020

The conditions you specified can be written as:

if ( time >= ( 8 * 60 * 60 )) and ( time < ( 20 * 60 * 60 )) then 
  do:
    message "first shift".
  end.
 else
  do:
    message "second shift".
  end.

Upvotes: 1

Related Questions