By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,480 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,480 IT Pros & Developers. It's quick & easy.

Ordering Months in Calendar Order

P: 1
Hi There,

I am trying to order my months in calendar format (Jan, Feb, Mar...), but I can not. It only shows in alphabetical order (Apr,Aug,Dec..).
Does anyone now how I can change the order from alphabetic to calendar order?

Thanks in advance...
Jan 24 '08 #1
Share this Question
Share on Google+
2 Replies


Jim Doherty
Expert 100+
P: 897
Hi There,

I am trying to order my months in calendar format (Jan, Feb, Mar...), but I can not. It only shows in alphabetical order (Apr,Aug,Dec..).
Does anyone now how I can change the order from alphabetic to calendar order?

Thanks in advance...
How are you arriving at your month values? if they derived from a formatting a date field then simply create a view that looks at that date field and expresses it as a month like this

MonthNum: MONTH(NameOfYourDateField])

This will then give you the numeric 1 - 12 values that you can sort on

So a typical select SQL statement would look something like this in a view (or stored procedure)

SELECT FirstName,Surname,DateOfBirth,MONTH([DateOfBirth]) as MonthNum FROM dbo.tblMyTable

You then get the extra column useful for sorting your recordset in the manner you need, in your displayed recordset when the view is run


Jim
Jan 24 '08 #2

deepuv04
Expert 100+
P: 227
Hi There,

I am trying to order my months in calendar format (Jan, Feb, Mar...), but I can not. It only shows in alphabetical order (Apr,Aug,Dec..).
Does anyone now how I can change the order from alphabetic to calendar order?

Thanks in advance...

try the following example ...
will help you


declare @table table (id int,date datetime)

select DATENAME(month, CONVERT(datetime,getdate(), 113))
insert into @table values(1,getdate())
insert into @table values(2,dateadd(month,1,getdate()))
insert into @table values(4,dateadd(month,2,getdate()))
insert into @table values(3,dateadd(month,3,getdate()))
insert into @table values(6,dateadd(month,4,getdate()))
insert into @table values(5,dateadd(month,5,getdate()))

--select * from @table

select id,convert(varchar(3),datename(month,date)) from @table order by date

thanks
Jan 24 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.