Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

check time between 2 times

Former Member
0 Kudos

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

8 REPLIES 8

Former Member
0 Kudos

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

0 Kudos

sorry ,but i need to know if the time is falling between two times.not the diffrence between two times.

0 Kudos

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.

0 Kudos

and if between 1800 to 0600 and its 2300?

0 Kudos

>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.

Former Member
0 Kudos

This message was moderated.

former_member184158
Active Contributor
0 Kudos

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

0 Kudos

Thanks for answer,best solution for time comparison, good work..