khan16
khan16

Reputation: 113

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)

Upvotes: 7

Views: 37893

Answers (2)

Shakeer Hussain
Shakeer Hussain

Reputation: 2526

you can you Format function.

SELECT FORMAT(GETDATE(), 'MMddyyyy') AS FormatDate

result: 10142024

Upvotes: 0

SoulTrain
SoulTrain

Reputation: 1904

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

Upvotes: 18

Related Questions