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

Time Difference

Former Member
0 Likes
665

Hi All

Am trying to find out time difference and add hours to it. The following is what I am trying to do:

In the following case lets assume the system time to be 12:30:20'.

DATA : lv_end_time TYPE uplend VALUE '130000',

lv_total_hours_to_add type i value 5,

lv_hours_done type uplend,

lv_hours_left type ???????.

lv_hours_done = lv_end_time - sy-uzeit. (will have '00:29:40').

Now I want to subtract this from the lv_total_hours_to_add and store the result in

So in my lv_hours_left, I want the value 4 hours 30 minutes and 20 seconds, how would I do this. I tried all the function modules suggested in the forum but still am unable to figure it out, guess its that part of the day where my mind goes to hibernation :).

Would appreciate help with the above.

Thanks

Sunil Achyut

3 REPLIES 3
Read only

Former Member
0 Likes
562

Found out the answer myself. Easier than what I thought, will post the solution I have.

Sunil Achyut

Read only

0 Likes
562

Here my solution, may not be sleek but serves the purpose :).

REPORT zsa_temp2.

DATA : lv_end_time TYPE uplend VALUE '140000',

lv_seconds TYPE sytabix,

lv_total_seconds TYPE sytabix,

lv_rem_seconds TYPE sytabix,

lv_temp_hours TYPE uplend.

lv_total_seconds = 5 * 60 * 60.

CALL FUNCTION 'SWI_DURATION_DETERMINE'

EXPORTING

start_date = sy-datum

end_date = sy-datum

start_time = sy-uzeit

end_time = lv_end_time

IMPORTING

duration = lv_seconds.

lv_rem_seconds = lv_total_seconds - lv_seconds.

lv_rem_seconds = lv_rem_seconds MOD 86400.

lv_temp_hours = lv_rem_seconds.

WRITE 😕 lv_temp_hours.

Thanks

Sunil Achyut

Read only

Former Member
0 Likes
562

You could make lv_total_hours_to_add and lv_hours_left the same type as the other time fields (uplend) and set the value to '050000'. Then you should be able to just use:

lv_hours_left = lv_total_hours_to_add - lv_hours_done.

I hope this helps.

- April King