08-17-2008 12:35 PM
Hi;
i need to know if time is between two times.for example :
if 01:00 is between 18:00 to 07:00.
How should i do it?is there any function?
the time of the fields is TIMS.
Thank you very much!!!
David
08-17-2008 12:44 PM
Hi David,
Check these function modules:
SD_CALC_DURATION_FROM_DATETIME : Finds the difference between two date/time and report the difference in hours
L_MC_TIME_DIFFERENCE : Finds the time difference between two date/time
Regards,
Chandra Sekhar
08-17-2008 12:46 PM
sorry ,but i need to know if the time is falling between two times.not the diffrence between two times.
08-17-2008 1:16 PM
I have a small question..here?
time is depends on the Date, if you don't consider the date you may get wrong results.
if you are working with the same Date then..
you can do some thing like this..
REPORT ZTEST_TIME.
data: r_time type range of sy-uzeit,
w_time like line of r_time.
data: current_time type sy-uzeit.
*06:00 is between 01:00 to 07:00.
w_time-low = '010000'.
w_time-high = '070000'.
w_time-sign = 'I'.
w_time-option = 'BT'.
append w_time to r_time.
current_time = '060000'.
if current_time in r_time.
write 'in the range'.
else.
write 'not in the range'.
endif.
08-18-2008 9:14 AM
08-18-2008 9:21 AM
>and if between 1800 to 0600 and its 2300?
There is a day change so it will fail in this case, as i suggested when you are considering the Time, you have to consider the date also. Otherwise you will get wrong results.
you check with 1800 to 2400 and current time is 2300
this works. you have to take care of Day change also.
06-17-2015 4:49 AM
04-18-2019 9:22 AM
Hello
I know this question is really old, but I would like to answer this question because I have the same question and answer. I found this code in SAP to check if break is in the time interval or not.
PARAMETERS:
beguz TYPE dienst_von,
enduz TYPE dienst_bis,
pabeg TYPE pdbeg,
paend TYPE pdend.
DATA: m_pabeg(5),
m_paend(5),
m_beguz(5),
m_enduz(5),
time24(6) VALUE '240000',
char_time(6),
char_pabeg(6),
char_paend(6),
char_beguz(6),
char_enduz(6),
num_pabeg(6) TYPE n,
num_paend(6) TYPE n,
num_beguz(6) TYPE n,
num_enduz(6) TYPE n.
DATA rv_subrc LIKE sy-subrc.
START-OF-SELECTION.
CLEAR rv_subrc.
* Conversion into calculated times:
char_pabeg = pabeg.
IF paend <= pabeg OR
paend < beguz.
char_time = paend.
char_paend = char_time + time24.
ELSE.
char_paend = paend.
ENDIF.
char_beguz = beguz.
IF enduz <= beguz.
char_time = enduz.
char_enduz = char_time + time24.
ELSE.
char_enduz = enduz.
ENDIF.
IF pabeg < beguz.
char_time = pabeg.
char_pabeg = char_time + time24.
ELSE.
char_pabeg = pabeg.
ENDIF.
num_pabeg = char_pabeg.
num_paend = char_paend.
num_beguz = char_beguz.
num_enduz = char_enduz.
IF num_pabeg < num_beguz.
IF num_paend < num_beguz.
MESSAGE 'Break begins before the time interval.' TYPE 'I'.
rv_subrc = 4.
ENDIF.
IF num_paend <= num_enduz.
* Break cuts the time interval at the beginning:
MESSAGE 'Break cuts the time interval at the beginning:.' TYPE 'I'.
rv_subrc = 4.
ENDIF.
IF num_paend > num_enduz.
* Break is after the end of the time interval:
MESSAGE 'Break is after the end of the time interval.' TYPE 'I'.
rv_subrc = 4.
ENDIF.
ENDIF.
IF num_pabeg >= num_beguz.
* Break starts in or directly at the time interval:
IF num_paend <= num_enduz.
* Break is in the time interval --> OK !!!
MESSAGE 'Break is in the time interval --> OK !!!' TYPE 'I'.
CLEAR rv_subrc.
ENDIF.
IF num_paend > num_enduz.
* Break cuts the time interval at the end:
MESSAGE 'Break cuts the time interval at the end:' TYPE 'I'.
rv_subrc = 4.
ENDIF.
ENDIF.
IF num_pabeg > num_enduz.
* Break is completely after the time interval:
MESSAGE 'Break is completely after the time interval' TYPE 'I'.
rv_subrc = 4.
ENDIF.
Best regards
Ebrahim
04-11-2020 12:08 PM