Click here to Skip to main content
15,904,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the month as
Jan 
Feb 
May

Only 3 characters.

--What i have tried :
SQL
select SUBSTRING(datename(month,getdate()),1,3)


Kindy suggest is there any other function/way which can solve the problem.
Posted
Updated 13-Nov-13 0:30am
v2

How about this -

SQL
select left(datename(month, GetDATE()),3)
 
Share this answer
 
Comments
anurag19289 13-Nov-13 7:01am    
Super...
You could also use
SQL
CONVERT(VARCHAR(3),GETDATE())

as 'mmm dd yyyy hh:mi[AM|PM]' is the default format for date conversion, and VARCHAR(3) will just return the first 3 characters
 
Share this answer
 
Comments
Thava Rajan 13-Nov-13 6:55am    
SELECT CAST(GETDATE() AS VARCHAR(3))

also worked
CHill60 13-Nov-13 8:29am    
Yes - and a little more elegant than my suggestion - a virtual 5!
anurag19289 13-Nov-13 7:02am    
That is nice :)
You Should Also Use:


select convert(char(3), ColumnName, 0) as AliasName from tableName

Above "ColumnName" From Your Table And "AliasName" For Duplicate Name
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900