How to get month number like Jan -01, Feb-02 ... Instead of Jan-1, Feb-2

  • Hi,

    Need help on get month number from Date field, I am getting month number as 1 for Jan, 2 for Feb

    But I need 01 for Jan, 02 for Feb..like this

    Can you please some one help me out

    Thanks

    Grace

  • try this and see if it helps:

    select right('0' + cast(month(getdate()) as varchar),2)

  • Or maybe a little "silent truncation" (one of my favorite tools) is in order.

    SELECT CONVERT(CHAR(2),GETDATE(),1)

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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