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: 

To calculate the difference between timings ( PM - AM )

Former Member
0 Kudos

Hi All,

Can anyone let me know how to calculate the difference between the time.

EG : From time : 23:00:00 pm

To time : 01:00:00 am

instead of 2 hours we are getting 22 Hrs

Thanks in Advance

Sathyapriya

7 REPLIES 7

Former Member
0 Kudos

Use FM: SD_DATETIME_DIFFERENCE. You need to specify the dates as well to calculate the difference orelse system will not know whether you meant the same day or different dates.

Former Member
0 Kudos

Check this sample code without using FM.

parameters: p_tim1 type uzeit,   " 23:00:00
            p_tim2 type uzeit. " 01:00:00

data: l_diff type uzeit.

start-of-selection.

  l_diff = p_tim2 - p_tim1.

  write:/ l_diff.

0 Kudos

Hi,

Thanks for the reply.

But i have to calculate the diffrence for nearly 30 fields.

The user will be entering raw data like say

lunch hours, he will enter it as

lunch from time : 13:00:00 lunch to time : 14:00:00

in this fashion there are other 30 fields...

Can u plz tell me how to solve this problem.

Thanks N Regards,

Sathyapriya

0 Kudos

Difficult to propose a solution unless we know the whole set of conditions. Providing more details can help for better advices.

0 Kudos

Actually i have done a development for Excavators

wherein the user enters the following details

Say..

Lunch_hrs = Lunchtotime - lunchfromtime.

breakdown = breakdowntotime - breakdownfromtime

in this way there is

machine maintenence

HSD Filling

machine Shifting hrs

and so on upto 30 fields

This particular machine works for 3 shifts..

1st shift from 07:00:00 AM to 13:00:00 PM

2nd shidt from 13:00:00PM to 23:00:00PM

3rd shift from 23:00:00PM to 07:00:00AM

but i am facing a problem while calculating the time difference for the third shift.

Kindly help me to solve this problem as this very urgent.

Thanks,

Priya

0 Kudos

Hi Priya, How about using FM: HR_PDC_ADD_24_HOURS

PARAMETERS: p_tim1 TYPE uzeit,                              " 23:00:00
            p_tim2 TYPE uzeit.                              " 01:00:00

DATA: l_diff TYPE uzeit.

START-OF-SELECTION.

  IF p_tim1 > p_tim2.
    CALL FUNCTION 'HR_PDC_ADD_24_HOURS'
      CHANGING
        logical_time = p_tim2.
  ENDIF.
  l_diff = p_tim2 - p_tim1.
  WRITE:/ l_diff.
As you are saying you have 30 fields to calculate, make a subroutime instead of calculating everytimg like:
  PERFORM cal_tim_diff USING p_tim1 p_tim2
                    CHANGING l_diff.
*&---------------------------------------------------------------------*
*&      Form  CAL_TIM_DIFF
*&---------------------------------------------------------------------*
FORM cal_tim_diff  USING    p_tim1 TYPE uzeit
                            p_tim2 TYPE uzeit
                   CHANGING p_diff TYPE uzeit.

  IF p_tim1 > p_tim2.
    CALL FUNCTION 'HR_PDC_ADD_24_HOURS'
      CHANGING
        logical_time = p_tim2.
  ENDIF.
  p_diff = p_tim2 - p_tim1.

ENDFORM.                    " CAL_TIM_DIFF
If it still doesnt help, check the data type of the time fields that you are considering.

Former Member
0 Kudos

Hi,

data : lv_start(10), lv_end(10) .

data : lv_final(10).

data:w_temp type i,

w_diff like sy-uziet.

lv_start = '10:25:30'.

lv_end = '10:50:30'.

w_temp = lv_end - lv_start.

w_diff = w_temp.

CONCATENATE w_diff0(2) ':' w_diff2(2) ':' w_diff+4(2) INTO lv_final

write: / lv_final.