November 22, 2004 at 1:14 pm
How do I pull the month out of date, and convert it to a string value?
In other words, if the month is January, I want to pull out 01. February, I want 02 (but the output needs to be a string)
November 22, 2004 at 1:27 pm
select case when datepart(mm,getdate())<=9 then '0'+cast(datepart(mm,getdate())as varchar)
else cast(datepart(mm,getdate())as varchar) end
November 22, 2004 at 1:36 pm
OR:
select right('00'+ cast(month(getdate()) as varchar(2)),2)
* Noel
November 23, 2004 at 1:21 am
Another one:
SELECT REPLACE(STR(DATEPART(mm,GETDATE()),2), ' ', '0')
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
November 23, 2004 at 6:33 am
And, a totally different idea...
Create a table that has all the date conversions done, a dimension table. Then simply link to the table and pull only the month converted to text. By using a table, you essentailly never have to do any date conversions like this again.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply