11 Replies Latest reply: Jun 4, 2007 12:11 PM by soumya chakraborty RSS

CONVERT time to hh:mm:ss

soumya chakraborty
Currently Being Moderated

Hi ,

 

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

 

Thanks and regards ,

Soumya .

  • Re: CONVERT time to hh:mm:ss
    Amit Khare
    Currently Being Moderated

    Check the link -

    Time Format HH:MM:SS

     

    Regards,

    Amit

     

    Reward all helpful replies.

  • Re: CONVERT time to hh:mm:ss
    anitha averneni
    Currently Being Moderated

    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

  • Re: CONVERT time to hh:mm:ss
    Naveen Shetti
    Currently Being Moderated

    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).

  • Re: CONVERT time to hh:mm:ss
    Sreeram Kumar Madisetty
    Currently Being Moderated

    Hi Soumya

     

     

    use the WRITE statement..

     

    DATA: V_CHAR(8).

     

    WRITE: SY-UZEIT TO V_CHAR.

     

    WRITE: / V_CHAR.

     

     

    Thanks,

    Sree

  • Re: CONVERT time to hh:mm:ss
    Dev Parbutteea
    Currently Being Moderated

    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.

    • Re: CONVERT time to hh:mm:ss
      Dev Parbutteea
      Currently Being Moderated

      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.

  • Re: CONVERT time to hh:mm:ss
    Ravi kumar Balakrishnan
    Currently Being Moderated

    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

  • Re: CONVERT time to hh:mm:ss
    Kun Zhang
    Currently Being Moderated

    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.

  • Re: CONVERT time to hh:mm:ss
    Anil Madhavan
    Currently Being Moderated

    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

  • Re: CONVERT time to hh:mm:ss
    Currently Being Moderated

    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

  • Re: CONVERT time to hh:mm:ss
    soumya chakraborty
    Currently Being Moderated

    The question is answered

Actions