Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Date in Format MMMYY

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

like image 432
user1557886 Avatar asked Jan 16 '26 21:01

user1557886


2 Answers

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

SELECT FORMAT(GETDATE(), 'MMMyy')

like image 53
SaSH_17 Avatar answered Jan 19 '26 18:01

SaSH_17


SELECT REPLACE(RIGHT(CONVERT(VARCHAR(9), GETDATE(), 6), 6), ' ', '') AS [MMYY]
like image 20
Dilip Kr Singh Avatar answered Jan 19 '26 20:01

Dilip Kr Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!