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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to convert a numeric month to Charracter type

Author  Topic 

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2009-05-12 : 05:22:04
HI...

I ahve fired a query
Select Month(Getadte())
this is returnig the numerical no of month.
can some one tell me how i can convert it into Charrecter like

Select Month(Getdate()) gives 5
i want to be as "May"

please telll me if any one know....
Thanx

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-12 : 05:27:45
SELECT datename(month,getdate())


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2009-05-12 : 05:35:51
quote:
Originally posted by madhivanan

SELECT datename(month,getdate())


Madhivanan

Failing to plan is Planning to fail



This Works, Thanks For the quick help... :)
Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2009-05-12 : 05:57:23
quote:
Originally posted by madhivanan

SELECT datename(month,getdate())


Madhivanan

Failing to plan is Planning to fail



Madhivaan, i have a colum of datetime type having entries for all months of 2007 in format 'dd-mm-yyyy'

and i have fetch all the month of 2007 in the format like 'May or june or ....

Datename Function is returning full name of month
to reduce the name of month up to desireable 3 charr. i used Left () function
e.g. Left(Datename(month, Columnname)) to get month name's 3initial charracters.
But how can i sort the names in order Jan, FEB, MAR, APR...
Please look in this matter also.
Thanks
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-05-12 : 06:02:29
declare @t table(id int, dateval datetime)

insert into @t select 1,'1/1/2009'
insert into @t select 2,'3/1/2009'
insert into @t select 3,'2/1/2009'
insert into @t select 4,'7/1/2009'
insert into @t select 5,'5/1/2009'
insert into @t select 6,'11/1/2009'

select left(datename(month,dateval),3) from @t order by month(dateval)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-12 : 06:54:58
quote:
Originally posted by arorarahul.0688

quote:
Originally posted by madhivanan

SELECT datename(month,getdate())


Madhivanan

Failing to plan is Planning to fail



Madhivaan, i have a colum of datetime type having entries for all months of 2007 in format 'dd-mm-yyyy'

and i have fetch all the month of 2007 in the format like 'May or june or ....

Datename Function is returning full name of month
to reduce the name of month up to desireable 3 charr. i used Left () function
e.g. Left(Datename(month, Columnname)) to get month name's 3initial charracters.
But how can i sort the names in order Jan, FEB, MAR, APR...
Please look in this matter also.
Thanks



Your query should be just returning the date to your application and let the front end application display the the month name as JAN, FEB etc

or alternatively, you can return 2 column, one is the original date and the other is the month name

select [date], left(datename(month, [date]), 3)
from sometable
order by [date]



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2009-05-12 : 07:21:07
Thanks... this logic workd :) thanks for ur time
Go to Top of Page
   

- Advertisement -