Loading ...

Get month name from integer | CodeAsp.Net

Get month name from integer

 /5
0 (0votes)

In this blog I will explain you how to get month name from integer. Many times we have an integer which represent month index and we want the name of month corresponding to the month index.Below is the code snippet:

 

 

static void Main(string[] args)

{

int monthIndex = 11;

Console.WriteLine(string.Format("Full month name : {0}",GetFullMonthName(monthIndex)));

Console.WriteLine(string.Format("Abbreviated month name: {0}", GetAbbreviatedMonthName(monthIndex)));

Console.ReadLine();

}

static string GetFullMonthName(int monthIndex)

{

DateTime date = new DateTime(1, monthIndex, 1);

return date.ToString("MMMM");

}

static string GetAbbreviatedMonthName(int monthIndex)

{

DateTime date = new DateTime(1, monthIndex, 1);

return date.ToString("MMM");

}

 

 

 

Happy Reading.!

 

 

Comments (no comments yet)

Top Posts