need to convert date to MMYYYY format

Hi experts, I have a column with smalldatetime format ex:2005-02-26 11:39:00 , I need to convert this to
MMYYYY format (022005 should be my result).
Pls help
sqlcuriousAsked:
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.

DALSOMCommented:
Hi,
Try this :
declare @hr smalldatetime
set @hr = GETDATE()  -- @hr must be replace by your field at select statement.
select right(CONVERT(varchar(6),@hr,112),2) + left(CONVERT(varchar(6),@hr,112),4) as [My Date]

hope this help!
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
vincem1099Commented:
Try this:

select STR(MONTH(getdate()),2)+str(DAY(getdate()),2)+str(YEAR(getdate()),4)

Replace getdate() with your date variable/column name
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.

sqlcuriousAuthor Commented:
Thanks all but none of the above answers helped :
0
vincem1099Commented:
This works even better to show single digit months and days with a leading 0 :

select replace(convert(char,getdate(),10),'-','')
0
LowfatspreadCommented:
like this

?


select right('0'+datename(mm,Yourdate),2)+datename(yy,Yourdate) as MMYYYY
0
sqlcuriousAuthor Commented:
I did this and it worked:
SELECT ((SUBSTRING(REPLACE((CONVERT(VARCHAR(8), '2005-02-26 11:39:00', 112)), '-', ''),5,6)+(SUBSTRING(REPLACE((CONVERT(VARCHAR(8), '2005-02-26 11:39:00', 112)), '-', ''),1,4))))

and also for DALSOM's answer if I change it to
select right(CONVERT(varchar(7),'2005-02-26 11:39:00',112),2) + left(CONVERT(varchar(6),'2005-02-26 11:39:00',112),4)
it works, so assigning partial points to DALSOM.
Thanks!
0
sqlcuriousAuthor Commented:
thanks
0
vincem1099Commented:
I think this will work:

select left(replace(convert(char,Yourdate,110),'-',''),2)+RIGHT(rtrim(replace(convert(char,YourDate,110),'-','')),4)
0
Anthony PerkinsCommented:
How complicated.  Surely this would be better:
RIGHT(REPLACE(CONVERT(varchar(10), '2005-02-26 11:39:00', 103), '/', ''), 6
0
Scott PletcherSenior DBACommented:
All way too complicated ! :

SELECT
    STUFF(CONVERT(varchar(10), GETDATE(), 101), 3, 4, '')

Naturally replace GETDATE() with your own date.

0
Anthony PerkinsCommented:
Good one.
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.