DateTime format to mmmdd format

  • Then you've missed a space from what I wrote. Here it is with * instead of space.

    Replace(Replace(Convert(Char(6),@thedate,109),'**','0'),'*','')

    The concept is that you need to find the scenario where there are 2 spaces, and put a leading zero in there. But just remove a single one.

    Rob Farley
    LobsterPot Solutions & Adelaide SQL Server User Group
    Company: http://www.lobsterpot.com.au
    Blog: http://blogs.lobsterpot.com.au

  • >I cannot get Jeff's solution to work without using GETDATE(). 

    What I wrote was meant to solve the original posting which stated... "I would like to be able to convert SQL server DateTime format to the format mmmdd."

    Things like '20050101' are not SQL DateTime data types... they're text.

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

  • Thanks Rob

     Select Replace(Replace(Convert(Char(6),@thedate,109),'**','0'),'*','') 

    Works great (FYI I cut and pasted from your original post

     

    Mike

Viewing 3 posts - 16 through 17 (of 17 total)

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