Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
wembleybear
Yak Posting Veteran
93 Posts |
Posted - 2013-12-13 : 05:11:56
|
I'm trying to return the month part of the current date, along with the month number. I want it to return:01 - January02 - February, etcIt's fine for October to December, but for the other nine months my code returns 1 - January and I want to be sure the leading 0 is added. How can I do this? Here is my current code:CONVERT(nvarchar,MONTH(Getdate())) + ' - ' + DATENAME(MONTH,Getdate()) as MonthName Many thanksMartyn |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-12-13 : 05:16:51
|
right('00'+CONVERT(nvarchar,MONTH(Getdate())),2) + ' - ' + DATENAME(MONTH,Getdate()) as MonthName Too old to Rock'n'Roll too young to die. |
 |
|
wembleybear
Yak Posting Veteran
93 Posts |
Posted - 2013-12-13 : 05:36:00
|
Works perfectly, thank you!Martyn |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-13 : 06:45:03
|
REPLACE(STR(MONTH(Getdate()),2),' ','0')+ ' - ' + DATENAME(MONTH,Getdate()) as MonthName------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-12-24 : 07:37:16
|
In version 2012 onwards, SELECT format(getdate(),'MM-MMMM')MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|