Add zero before digit

  • Hello,

    How can I have the minutes with 2 digit every time ?

    Regards. 

    1> select datename(minute, getdate())

    2> go

     ------------------------------

     5

     

    Expected :

     ------------------------------

     05

  • Hi

    Try this out

    SELECT RIGHT('0'+DATENAME(MINUTE,GETDATE()),2)

    Ram

  • Why do you need to do this??  Formatting is usually better off done client side!

     

    SELECT RIGHT('0' + CONVERT(VARCHAR(2), DATEPART(n, GETDATE())), 2) AS StrMin

  • Thank you Sriram !

     

    It's allright !

     

    Regards

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply