2

How to get current date in sql to MMMYY i.e. OCT13

select Convert(varchar(10),getdate(),6) this will generate 11 Oct 13

I need to get OCT13 .

Any help appreciated.

Front end application cannot do this formating. I am exporting the data from sql to another sql server Thanks

2
  • Why do you want to do it in SQL, why not just get the raw datetime value and alter how it appears in your consuming application?
    – Dai
    Oct 11, 2013 at 6:00
  • Why not handle the formatting on the front end?
    – lc.
    Oct 11, 2013 at 6:00

4 Answers 4

8

With the FORMAT Function its very easy to convert it to the right format: (for SQL Sever 2012)

SELECT FORMAT(GETDATE(), 'MMMyy')

0
7
SELECT REPLACE(RIGHT(CONVERT(VARCHAR(9), GETDATE(), 6), 6), ' ', '') AS [MMYY]
1
  • Or slightly shorter SELECT REPLACE(CONVERT(VARCHAR(6), GETDATE(), 0),' ','')
    – OlleR
    Oct 11, 2013 at 6:28
1
SELECT UPPER(REPLACE(RIGHT(CONVERT(VARCHAR(9), GETDATE(), 6), 6), ' ', '')) AS [Mon-YY]
0

In Oracle "DD-MON-YY" would work (you can try MON-YY in your case). TO_DATE(sysdate, 'MON-YY')

Also give this a try in SQL server:

UPPER(SUBSTRING(CONVERT(varchar, dt, 13), 4, 3)) +
SUBSTRING(CONVERT(varchar, dt, 13), 1, 2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.