none
Add leading zero in timefield

    Question

  • Hi All,
    I have a table with 2 columns, let say ID as Int and TimeField as Varchar(8)

    ID  TimeField
     1    1:15
     2    8:45
     3    12:30
     4    10:00
     5    8:30

    I want leading 0 to be added before  the timefield for the Id's=1,2 and 5

    My output should look like this..


    ID  TimeField
     1    01:15
     2    08:45
     3    12:30
     4    10:00
     5    08:30

    Thanks,
    RH


    sql


    • Edited by sql9 Wednesday, July 02, 2014 3:40 PM Updated data Types
    Wednesday, July 02, 2014 3:37 PM

Answers

  • declare @date varchar(5)='1:30'
    select RIGHT('0'+ CONVERT(VARCHAR(6),@date),5)
    --Prashanth
    • Marked as answer by sql9 Wednesday, July 02, 2014 3:45 PM
    Wednesday, July 02, 2014 3:43 PM

All replies