0

I have a table named NewsMaster which has a column named NewsDate .

Date is stored as 2016-05-19 00:00:00.000 in this table.

Now i want to retrieve this date as something like October-2016 . that's it. looked so many blogs but nothing found.

DATENAME(month,GETDATE()) 'Month Name'

is this helpful? am i close? need modification.

3
  • FORMAT() or DATENAME(MONTH, col) + '-' + DATENAME(YEAR, col) Commented May 26, 2016 at 11:07
  • Can U please describe more? Commented May 26, 2016 at 11:07
  • SELECT DATENAME(MONTH, NewsDate) + '-' + DATENAME(YEAR, NewsDate) FROM NewsMaster Commented May 26, 2016 at 11:18

2 Answers 2

2

Try this

Select DATENAME(month,GETDATE())+' - '+ convert(nvarchar,DATEPART(yyyy,GETDATE()))
Sign up to request clarification or add additional context in comments.

Comments

1

You can use Format() function introduced in sql server 2012. Try this -

SELECT FORMAT(CAST('2016-05-19' AS DATE), 'MMM-yyyy')

Result

May-2016

You can use it in your query like this -

SELECT FORMAT(NewsDate, 'MMM-yyyy') AS NewsDate FROM yourTable

3 Comments

my column name is NewsDate
'FORMAT' is not a recognized built-in function name. this is the error in your query
@DinavAhire: Are you sure you are using SQL Server 2012 ? check your instance\

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.