How to extract only mm/yyyy

I can't seem to figure this out.

I have the following select statement:

select expire_date AS EXPIREDATE

right now, it returns mm/dd/yyyy along with the time. How can I extract only mm/yyyy? Tried using both cast and convert, couldn't get this to work.
IUAATechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberkiwiCommented:
substring(convert(varchar(8), expire_date, 103), 4,10)
0
cyberkiwiCommented:
Sorry, please use this
select substring(convert(varchar(20), getdate(), 103), 4, 7)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LowfatspreadCommented:
select  stuff(reverse(convert(char(6),expire_date,112)),3,0,'\') as mmyyyy
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

IUAATechAuthor Commented:
Ok. I have the following query.

select substring(convert(varchar(20), expire_date, 103), 4, 7) AS EXPIREDATE, member_type AS MEMBERTYPE, count(person_id) AS TOTAL
from memberships
where membership = 'M' AND expire_date >= @StartDate AND expire_date < DATEADD(dd, 1, @EndDate)
group by substring(convert(varchar(20), expire_date, 103), 4, 7), member_type
order by EXPIREDATE desc

Is this how I do a "group by" on the expire_date?

As for the "order by", the outcome is inconsistent.

I get 12/2009, then 3/2010, 2/2010 and 1/2010.

any suggestion?
0
IUAATechAuthor Commented:
nevermind. the following seems to work.

select substring(convert(varchar(20), expire_date, 103), 4, 7) AS EXPIREDATE, member_type AS MEMBERTYPE, count(person_id) AS TOTAL
from memberships
where membership = 'M' AND expire_date >= @StartDate AND expire_date < DATEADD(dd, 1, @EndDate)
group by expire_date, member_type
order by expire_date
0
LowfatspreadCommented:
thats because expire date is a string not a date now so that order is correct...

try

select substring(convert(char(20), expire_date, 103), 4, 7) AS EXPIREDATE, member_type AS MEMBERTYPE, count(person_id) AS TOTAL
from memberships
where membership = 'M' AND expire_date >= @StartDate AND expire_date < DATEADD(dd, 1, @EndDate)
group by substring(convert(char(20), expire_date, 103), 4, 7), member_type
order by convert(datetime,'01/'+ EXPIREDATE) desc
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.