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!

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
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

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

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

?


select right('0'+datename(mm,Yourdate),2)+datename(yy,Yourdate) as MMYYYY
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!
sqlcuriousAuthor Commented:
thanks
vincem1099Commented:
I think this will work:

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

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

Naturally replace GETDATE() with your own date.

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