Reputation: 77
I would like to insert 2 shift timings to the code.
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
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
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