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: 

CONVERT time to hh:mm:ss

Former Member
0 Kudos

Hi ,

Please give me any idea of converting time in seconds to hh:mm:ss .

Thanks and regards ,

Soumya .

11 REPLIES 11

amit_khare
Active Contributor
0 Kudos

Check the link -

Regards,

Amit

Reward all helpful replies.

Former Member
0 Kudos

Hi,

DATA: lv_hours TYPE i,

lv_minutes TYPE i,

lv_seconds TYPE i.

lv_hours = lv_seconds / 3600.

lv_seconds = lv_seconds - lv_hours * 3600.

lv_minutes = lv_seconds / 60.

lv_seconds = lv_seconds - lv_minutes * 60.

thanks,

Anitha

Former Member
0 Kudos

HI,

use this piece of code. or goto SPFLI table field FLTIME and check the conversion routine SDURA in domain S_DURA

LENGTH = STRLEN( INPUT ).

IF LENGTH > 6.

MESSAGE E250.

ENDIF.

TEMP = INPUT.

  • initial?

  • IF temp = ' 0:00'.

  • output = 0.

  • EXIT.

  • ENDIF.

  • Remove leading ' '

SHIFT TEMP LEFT DELETING LEADING ' '.

  • Non numericals?

IF NOT TEMP CO '1234567890: '.

MESSAGE E250.

ENDIF.

  • ' ' not only at the end?

LENGTH = STRLEN( TEMP ).

DO.

OFFSET = SY-INDEX - 1.

TEMP_C = TEMP+OFFSET(1).

IF TEMP_C = ' '.

MESSAGE E250.

ENDIF.

IF SY-INDEX = LENGTH.

EXIT.

ENDIF.

ENDDO.

IF TEMP CS ':'.

  • input contains hours and minutes

SPLIT TEMP AT ':' INTO HOURS_C MINUTES_C.

IF SY-SUBRC <> 0

OR HOURS_C = SPACE

OR NOT HOURS_C CO '1234567890 '

OR MINUTES_C = SPACE

OR NOT MINUTES_C CO '1234567890 '.

MESSAGE E250.

ENDIF.

LENGTH = STRLEN( MINUTES_C ).

IF LENGTH <> 2.

MESSAGE E250.

ENDIF.

OUTPUT = HOURS_C * 60 + MINUTES_C.

  • WRITE minutes_c TO output.

ELSE.

  • input contains minutes only

OUTPUT = TEMP.

ENDIF.

HOURS = INPUT DIV 60.

MINUTES_N = INPUT MOD 60.

WRITE HOURS TO OUTPUT(3) NO-SIGN.

OUTPUT+3(1) = ':'.

WRITE MINUTES_N TO OUTPUT+4(2).

sreeramkumar_madisetty
Active Contributor
0 Kudos

Hi Soumya

use the WRITE statement..

DATA: V_CHAR(8).

WRITE: SY-UZEIT TO V_CHAR.

WRITE: / V_CHAR.

Thanks,

Sree

dev_parbutteea
Active Contributor
0 Kudos

Hi,

am just modifying the above codes to make it wort better

DATA: lv_hours TYPE i,

lv_minutes TYPE i,

lv_seconds TYPE i,

temp(8) type c.

lv_hours = lv_seconds / 3600.

lv_minutes = lv_seconds / 60.

if lv_hours > 0 and lv_hours < 24.

lv_seconds = lv_seconds - (lv_hours * 3600 + lv_minutes * 60).

endif.

if lv_minutes > 0 and lv_hours < 0 .

lv_seconds = lv_seconds - lv_minutes * 60.

endif.

concatenate lv_hours lv_minutes lv_seconds into temp seperated by ':' .

Regards,

Sooness.

0 Kudos

Hi,

am just modifying the above codes to make it wort better

DATA: lv_hours TYPE i,

lv_minutes TYPE i,

lv_seconds TYPE i,

temp(8) type c.

lv_hours = lv_seconds / 3600.

lv_minutes = lv_seconds / 60.

if lv_hours > 0 and lv_hours < 24.

lv_seconds = lv_seconds - (lv_hours * 3600 + lv_minutes * 60).

<b>elseif</b> lv_minutes > 0 and lv_hours < 0 .

lv_seconds = lv_seconds - lv_minutes * 60.

endif.

concatenate lv_hours lv_minutes lv_seconds into temp seperated by ':' .

Regards,

Sooness.

Former Member
0 Kudos

Hi

DATA: lv_hours TYPE i,

lv_minutes TYPE i,

lv_seconds TYPE i.

lv_hours = lv_seconds / 3600.

lv_seconds = lv_seconds - lv_hours * 3600.

lv_minutes = lv_seconds / 60.

lv_seconds = lv_seconds - lv_minutes * 60.

Concatenate all the fields into a variable. And display that variable using below write statement.

WRITE (8) TIME USING EDIT MASK '__:__:__'. "Output: 15:46:33

Reward me if its helpful

Regards

Ravi

Former Member
0 Kudos

hi,

i wander if i understand you correctly,

following is my test.

report test.

data: sec type i value 10920,

hh,

mm,

ss,

temp type i,

sep type c value ':',

time(20) type c.

hh = sec div 3600.

temp = sec mod 3600.

mm = temp div 60.

ss = temp mod 60.

concatenate hh sep mm sep ss into time.

write:/ time.

Former Member
0 Kudos

Hi Soumya,

You can use the function module <b>CONVERSION_EXIT_SDURA_OUTPUT</b>

This function module takes minutes as input and gets the time back in HH:MM format.

So convert the seconds into minutes by dividing by 60, and call the function.

Regards

Anil Madhavan

Former Member
0 Kudos

Hi,

If you want to write to list

use EDIT MASK

if you want to move to another field

use

WRITE TO <Field name> & specify the format / edit mask

Hope you find it useful

Regards,

Guarav

Former Member
0 Kudos

The question is answered