Skip to content
Advertisement

convert date yyyy-mm-dd to mmm-yy SQL Server 2016

I want to convert date yyyy-mm-dd (stored as a date format) to mmm-yy format.

There are no exact matches in the prior questions on the site.

I have tried substrings and convert function, was considering creating a scalar function but its taking me a while and hoping someone has an easy solution.

Advertisement

Answer

You can construct the format using string operations:

select left(datename(month, datecol), 3) + '-' + right(datename(year, datecol), 2)

Or using format():

select format(datecol, 'MMM-yy')
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement