Friday, March 23, 2012

Month Name

I am trying to get the month name out of the date but need only the short form, like Aug and not August, Sep for September etc..

I am using the following to achieve this:

DateName(month, GetDate( )) = June

LEFT(DateName(month, GetDate( )),3) = Jun

Which does the trick. But is there an elegant way of returning short month name?

Thx.

Nope.. We have onlye Left & datename.. You are on the rite track...

Following query is another trick

Select Cast(Datename(Month,getdate()) as Char(3))

|||

Hmmm. I guess there is only one more way...its ugly too

SubString(DateName(month, GetDate( )), 1, 3)

!!

|||

Code Snippet

selectconvert(char(3),getdate(), 0)

|||

And my personal favorite:

SELECT left( datename( month, getdate()), 3 )

sql

No comments:

Post a Comment