1

I need a small script to get the current month name and current year. So as to create a unique batch to store statements. My preferred format is January2011 or Feb2011 whichever is easier to get. i.e. MonthYear

3 Answers3

3

Try a query that looks like this:

SELECT DATENAME(month, GETDATE()), DATENAME(year, GETDATE());

You can find some more information over here.

Brecht
  • 107
  • 7
  • This would match the preferred format: SELECT DATENAME(month,GETDATE()) + DATENAME(year, GETDATE()) – Dubs Apr 12 '11 at 13:14
0

Have a look at the DATEPART function and combine that with finding the name of a month, this SO question/answer has information on doing that.

Community
  • 1
  • 1
Tony
  • 9,672
  • 3
  • 47
  • 75
0

You can use the following:

select datename(month,getdate()) + cast(datepart(year,getdate()) as char(4))
JStead
  • 1,710
  • 11
  • 12