5

I need to compute time difference in minutes with four input parameters, DATE_FROM, DATE_TO, TIME_FROM, TIME_TO. And one output parameter DIFF_TIME. I have created a function module, I need to write a formula which computes the time diff in minutes.

Any help would be great!

Thanks, Sai.

2

2 Answers 2

7

Use CL_ABAP_TSTMP=>TD_SUBTRACT to get the number of seconds between two date/time pairs.

(then, to get the number of minutes, divide the number of seconds by 60).

Example:

DATA(today_date) = CONV d( '20190704' ).
DATA(today_time) = CONV t( '000010' ).
DATA(yesterday_date) = CONV d( '20190703' ).
DATA(yesterday_time) = CONV t( '235950' ).

cl_abap_tstmp=>td_subtract(
  EXPORTING
    date1    = today_date
    time1    = today_time
    date2    = yesterday_date
    time2    = yesterday_time
  IMPORTING
    res_secs = DATA(diff) ).

ASSERT diff = 20. " verify expectation or short dump
2

If the values are guaranteed to be in the same time zone, it's easy enough that you don't need any special function module or utility method. Read this, then get the difference of the dates and multiply that by 24 * 60 and get the difference of the times (which is in seconds) and divide that by 60. Sum it up and there you are.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.