?
Solved

SQL date syntax

Posted on 2012-08-10
3
Medium Priority
?
605 Views
Last Modified: 2012-08-10
How do I create this 08,2012?.. The month has to be 2 digits
0
Comment
Question by:cheryl9063
  • 3
3 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38282087
-- 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
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 38282095
>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
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38282306
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question