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: 

How to subtract two given time

Former Member
0 Kudos

Hi

I need to subtract two time fields...

how to do that....

Cheers

Christina

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hiii

use FM L_MC_TIME_DIFFERENCE

take both field's value in variables and subtract

w_time = w_time1 - w_time2.

w_time will give you final time value.

regards

twinkal

7 REPLIES 7

Former Member
0 Kudos

hiii

use FM L_MC_TIME_DIFFERENCE

take both field's value in variables and subtract

w_time = w_time1 - w_time2.

w_time will give you final time value.

regards

twinkal

prasanth_kasturi
Active Contributor
0 Kudos

hi,

put the dates in two variables and do the normal subtraction

data : a type sy-uzeit ,

b type sy-uzeit.

a = sy-uzeit.

b = sy-uzeit + 1.

a = b - a.

write a.

regards

prasanth

Former Member
0 Kudos

Use below logic.

Data: t1 type sy-uzeit,

t2 type sy-uzeit,

td type sy-uzeit.

td = t1 - t2.

Regards,

0 Kudos

simple time1 - time2 will give your answer

0 Kudos

Result = TIME1 - TIME2.

Raghav

former_member217544
Active Contributor
0 Kudos

Hi,

Use the Function Module 'SALP_SM_CALC_TIME_DIFFERENCE'.

date format = 01/08/2008

time format = 01:30:20

CALL FUNCTION 'SALP_SM_CALC_TIME_DIFFERENCE'

EXPORTING

DATE_1 = '01082008'

TIME_1 = '013020'

DATE_2 = '01082008'

TIME_2 = '003010'

IMPORTING

SECONDS = SECONDS

.

WRITE seconds.

It will give the diffrence in the form of seconds (ss).

But if you want that in the format of mm:ss use edit mask concept.

DATA: time TYPE s_fltime,

msk TYPE string.

DESCRIBE FIELD time EDIT MASK msk.

CALL FUNCTION 'SALP_SM_CALC_TIME_DIFFERENCE'

EXPORTING

DATE_1 = '01082008'

TIME_1 = '013020'

DATE_2 = '01082008'

TIME_2 = '013010'

IMPORTING

SECONDS = SECONDS

.

WRITE seconds USING EDIT MASK msk.

Hope this will help.

Regards,

Swarna Munukoti

Former Member
0 Kudos

HI ,

Give output in hours as well as seconds .

CALL FUNCTION '/SDF/CMO_TIME_DIFF_GET'
    EXPORTING
      utc_start = w_usrformat1(YYYYMMDDHHMMSS)
      utc_end   = w_usrformat2
    IMPORTING
      second    = w_seconds
      hours       = w_hours
    EXCEPTIONS
      paramerr  = 1
      OTHERS    = 2.
  IF sy-subrc NE 0.
*    Do Nothing
  ELSE.