
DateTime.Month returns an integer. This value indicates the month in the year, from January to December. With a format string, we can get month names. The DateTime type provides all this functionality in the .NET Framework.
This C# article uses the DateTime Month property. It shows how to get month strings based on format strings.
First, here we look at how you can use the Month property on DateTime in the C# language. Month is an instance property getter in the language, which means you must call it on a DateTime instance, but not with parentheses. It returns an integer that is 1-based: January is equal to 1, and December is equal to 12.
Program that uses Month [C#]
using System;
class Program
{
static void Main()
{
//
// Get the current month integer.
//
DateTime now = DateTime.Now;
//
// Write the month integer and then the three-letter month.
//
Console.WriteLine(now.Month);
Console.WriteLine(now.ToString("MMM"));
}
}
Output
5
MayNote on format string. The preceding example code shows how you can use the MMM format string for month strings in the C# language. You can use the MMMM string (four Ms) for the complete month name.
DateTime Format
You may need to display the month name in a three-letter format. This is equivalent, in English, two taking a substring of the first three letters, but using the 3 Ms next to each other may be easier and more terse for your code. This example shows the 3-letter months.
Program that displays months [C#]
using System;
class Program
{
static void Main()
{
DateTime now = DateTime.Now;
for (int i = 0; i < 12; i++)
{
Console.WriteLine(now.ToString("MMM"));
now = now.AddMonths(1);
}
}
}
Output
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
JanHere we see how you can display the month string in full. You need to specify four Ms next to each other in the format string. The program below simply loops over the 11 next months after the time of writing, which happens to be in February.
Program that displays complete months [C#]
using System;
class Program
{
static void Main()
{
DateTime now = DateTime.Now;
for (int i = 0; i < 12; i++)
{
Console.WriteLine(now.ToString("MMMM"));
now = now.AddMonths(1);
}
}
}
Output
February
March
April
May
June
July
August
September
October
November
December
January
In your program, you may want to have a 12-element array with all the month strings in it. This would allow you to access the month string by its index, such as having month[1] being equal to January. This may require a 13-element array. You can do this with loops similar to the above two loops.

Here we looked at ways you can use month strings and get the month string from the DateTime type in the C# language. The base class library in the .NET Framework provides powerful DateTime methods and you do not need to manually type in month names in most cases. We noted ways you can enumerate all the string values in your C# program.
Time Representations