Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in minutes between 2 dates and times?

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.

like image 603
sailaja Avatar asked Feb 20 '23 01:02

sailaja


1 Answers

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
like image 101
Tiago A. Avatar answered Feb 27 '23 03:02

Tiago A.