Is there a predefined enumeration for Month in the .NET library?

Mark Rogers picture Mark Rogers · May 22, 2009 · Viewed 58.9k times · Source

I'm looking to see if there is an official enumeration for months in the .net framework.

It seems possible to me that there is one, because of how common the use of month is, and because there are other such enumerations in the .net framework.

For instance, there is an enumeration for the days in the week, System.DayOfWeek, which includes Monday, Tuesday, etc..

I'm wondering if there is one for the months in the year, i.e. January, February, etc?

Does anyone know?

Answer

Andy Mikula picture Andy Mikula · May 22, 2009

There isn't, but if you want the name of a month you can use:

CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName (DateTime.Now.Month);

which will return a string representation (of the current month, in this case). Note that GetMonth takes arguments from 1 to 13 - January is 1, 13 is a blank string.