sqlsql-server-2008

SQL date format conversion to MMDDYYYY


What's the best way to convert the following statement to show the MMDDYYYY format such as 02022013 without slashes or hyphens...

CONVERT (CHAR(10), A.POKFRM, 112)

Solution

  • You could take a formatting that gives you elements in order but with / or - and then replace the / or - to get your desired result.

    select REPLACE(CONVERT (CHAR(10), getdate(), 101),'/','')
    

    Result:

    02022015