Application Development and Automation 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: 
Read only

Function Module for the differences

Former Member
0 Likes
925

Hi,

Can you pl let me know the function module to find the difference between two times.

<b>Input</b> time1(hours:minits:seconds) time2 (hours:minits:seconds)

Need <b>output</b> in hours:minits:seconds

Regards

Badari

7 REPLIES 7
Read only

anversha_s
Active Contributor
0 Likes
898

hi,

use this

HR_PDC_CALCULATE_TIME_DIFF

rgds

anver

Read only

anversha_s
Active Contributor
0 Likes
898

hi,

u can use this also.

Z_PM_CALC_TIME_DIFFERENCE

rgds

anver

Read only

Former Member
0 Likes
898

Hi,

CALL FUNCTION <b>'SD_DATETIME_DIFFERENCE'</b>

EXPORTING

DATE1 = D1

<b> TIME1 = T1</b>

DATE2 = D2

<b> TIME2 = T2</b>

IMPORTING

DATEDIFF = D3

<b> TIMEDIFF = T3</b>

EXCEPTIONS

INVALID_DATETIME = 1

OTHERS = 2.

Regards

Sudheer

Read only

anversha_s
Active Contributor
0 Likes
898

hi badari,

try this also.

data: t1 type tims,

t2 type tims,

t3 type tims,

time_second type i.

t1 = '193030'.

t2 = '093000'.

t3 = t1 - t2.

time_second = ( 60 * t3+0(2) ) + ( 60 * t3+2(2) ) + t3+4(2).

write 😕 't1:-', t1 ,' t2:-', t2 , ' t3:-', t3.

write 😕 'time_second ' , time_second .

rgds

anver

Read only

0 Likes
898

use fm.

<b>'SD_DATETIME_DIFFERENCE'</b>

<b>or

SD_CALC_DURATION_FROM_DATETIME</b>

ex-


data : date1 type sy-datum,  
     date2 type sy-datum,    
   time1 type sy-uzeit,   
    time2 type sy-uzeit,   
    v_datediff type p,      
 v_timediff type p.      
 date1 = '20060101'.   
    date2 = sy-datum.    


   time1 = '010101'.     
  time2 = sy-uzeit.
CALL FUNCTION 'SD_DATETIME_DIFFERENCE'  
EXPORTING    
DATE1                  = DATE1   
TIME1                  = TIME1  
DATE2                  = DATE2   
TIME2                  = TIME2
IMPORTING  
DATEDIFF               = v_DATEDIFF   TIMEDIFF               = v_TIMEDIFF
*EARLIEST              = EARLIEST 
EXCEPTIONS  
 INVALID_DATETIME      = 1  
 OTHERS                = 2          .
IF SY-SUBRC <> 0. 
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.

Read only

anversha_s
Active Contributor
0 Likes
898

Hi again,

1. Difference is always returned in SECONDS.

2. use this code (just copy paste in new program)

REPORT abc.

data : t1 type sy-uzeit.

data : t2 type sy-uzeit.

DATA : DIFF TYPE I.

t1 = '090000'.

t2 = '100000'.

DIFF = T2 - T1.

WRITE 😕 DIFF.

u can manipulate the DIFF.

rgds

anver

Read only

Former Member
0 Likes
898

Hi Badari,

You can use the FM <b>L_MC_TIME_DIFFERENCE</b>.

Since this FM requires a FROM_DATE and TO_DATE you can pass SY-DATUM for both.

Hope this helps!

Regards,

Saurabh

Message was edited by: Saurabh Punshi