SQL date syntax

How do I create this 08,2012?.. The month has to be 2 digits
LVL 1
cheryl9063Asked:
Who is Participating?
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
>Are you trying to return MM{comma}YYYY?
If yes, then (replace @dt in the second line with whatever date you're trying to mainipulate)...

Declare @dt datetime = GETDATE()

SELECT CONVERT(VARCHAR(2), @dt,101) + ',' + CAST(YEAR(@dt) as char(4))
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
-- Here's two ways to do the the month with a leading zero
Declare @dt datetime = GETDATE()

SELECT 'Month with a leading zero', CONVERT(VARCHAR(2), @dt,101), RIGHT('0' + CAST(Month(@dt) as varchar(2)), 2)

Are you trying to return MM{comma}YYYY?
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.