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

Adding Times

Former Member
0 Likes
1,268

Hello,

I have to add times (hh:mm). how can i do this?

thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,231

Hi lois,

1. If we add times, DATE also comes in to picture.

2. Other wise

3. U can simply use time1 + time2

4. Just copy paste

5.

report abc.

data : tm1 type sy-uzeit.

data : tm2 type sy-uzeit.

data : tm3 type sy-uzeit.

tm1 = sy-uzeit.

tm2 = '034500'.

tm3 = tm1 + tm2.

write 😕 tm1.

write 😕 tm2.

write 😕 '----


'.

write 😕 tm3.

regards,

amit m.

15 REPLIES 15
Read only

Former Member
0 Likes
1,231

Hi

you can use this Fm.

C14B_ADD_TIME

regards,

Sumit.

Read only

Former Member
0 Likes
1,232

Hi lois,

1. If we add times, DATE also comes in to picture.

2. Other wise

3. U can simply use time1 + time2

4. Just copy paste

5.

report abc.

data : tm1 type sy-uzeit.

data : tm2 type sy-uzeit.

data : tm3 type sy-uzeit.

tm1 = sy-uzeit.

tm2 = '034500'.

tm3 = tm1 + tm2.

write 😕 tm1.

write 😕 tm2.

write 😕 '----


'.

write 😕 tm3.

regards,

amit m.

Read only

0 Likes
1,231

Hi,

Try

time1 + time2

Regards,

Tanveer.

<b>Please mark helpful answers</b>

Read only

0 Likes
1,231

Thanks very much for your interet and i want to ask also how can i show the rate of two time? how can i calculate this? for ex: 03:45:00/15:00:00 = 25%

thanks again.

Read only

0 Likes
1,231

Hi again,

1. just copy paste

2. it will give 25.

3.

report abc.

data : tm1 type sy-uzeit.

data : tm2 type sy-uzeit.

data : tm3 type sy-uzeit.

data : rt type i.

tm1 = '034500'.

tm2 = '150000'.

tm3 = tm2 / tm1.

write 😕 tm1.

write 😕 tm2.

write 😕 '----


'.

write 😕 tm3.

rt = 100 / tm3+4(2).

write 😕 '----


'.

write 😕 rt.

Read only

0 Likes
1,231

But when i use "tm2 = sy-uzeit", it does not give me right reponse:(

Read only

0 Likes
1,231

Hi again,

1. do like this.

2. this will convert both times,

into their respective SECONDS,

and divide,

and give accurate results, in 2 decimals.

3.

report abc.

data : tm1 type sy-uzeit.

data : tm2 type sy-uzeit.

data : rt type p decimals 2.

data : sec1 type i.

data : sec2 type i.

tm1 = '150000'. "--- bigger time

tm2 = '034500'.

tm2 = sy-uzeit.

sec1 = ( tm1(2) * 3600 ) + ( tm1+2(2) * 60 ) + ( tm1+4(2) ) .

sec2 = ( tm2(2) * 3600 ) + ( tm2+2(2) * 60 ) + ( tm2+4(2) ) .

rt = sec1 / sec2.

write 😕 tm1.

write 😕 tm2.

write 😕 '----


'.

write 😕 rt.

regards,

amit m.

Read only

0 Likes
1,231

Oh my god, i have an another problem:(, they registered time (not like hh:mm:ss) like this hh,mm,ss in database. how can i do all of this operations when time used hh,mm,ss.

thanks.

Read only

0 Likes
1,231

Hi again,

1. if time is stored in database,

as character data, with COMMA,

2. then we have to do some extra thing,

thats all.

3. just copy paste

REPORT ABC.

DATA : MYTIME(8) TYPE C.

DATA : T1 TYPE SY-UZEIT.

*----


MYTIME = '06,45,00'.

WRITE 😕 'BEFORE ' , MYTIME.

REPLACE ALL OCCURRENCES OF ',' IN MYTIME WITH ''.

T1 = MYTIME.

WRITE 😕 'AFTER ' , T1.

regards,

amit m.

Read only

0 Likes
1,231

thanks very much..

Read only

0 Likes
1,231

Finally, i excuse and i want to say something again. they registered time hh,mm. When i replace with :,it change like hh:mm:. And i can do operations when it ends with :.

Read only

0 Likes
1,231

Hi again,

1. When i replace with :,it change like hh:mm:.

We are NOT replacing COMMA with :

2. The time field,

does not have :.

3. it consists of data in this format,

HHMMSS

4. WHEN we display it using WRITE statement,

it AUTOMATICALLY SHOWS IN this format

HH:MM:SS

regards,

amit m.

Read only

0 Likes
1,231

i understood what you have done. but i must change hh,mm (my datas are in this form) to hh:mm for doing operations.

Read only

0 Likes
1,231

Hi again,

1. if u want to replace , with :

2. then

REPLACE ALL OCCURRENCES OF ',' IN MYTIME <b>WITH ':'.</b>

regards,

amit m.

Read only

Former Member
0 Likes
1,231

Use WRITE ... TO ...Option

REPORT ZADDTIME .

DATA: V_TIM1 TYPE T,

V_TIM2 TYPE T,

V_TIM3 TYPE SY-UZEIT.

<b>WRITE SY-UZEIT TO V_TIM1.</b>

<b>WRITE '034500' TO V_TIM2.</b>

V_TIM3 = V_TIM1 + V_TIM2.

WRITE: V_TIM3.