C#: Get Current Month Name and Short Name

We had a requirement to get the current month name and its short name (example- November|Nov). While DateTime class does not provide these methods out of .net framework, we had to create methods which gives the similar output.. We have created similar methods through Extension Methods supported with recent .net framework.

Extension methods can be used as instance methods and it uses “this” keyword as a parameter. They are static and they must be defined on static class.

Here is the solution:

using System;
using System.Globalization;

namespace TestConsoleApp
    class Program
        static void Main(string[] args)
            Console.WriteLine(DateTime.Today.Day + "." + DateTime.Today.Month + "." + DateTime.Today.Year);
            // Update: Similar functionality can be achieved through below statements also.
            // Thanks Michael for inputs.
            Console.WriteLine(String.Format("{0:MMMM}", DateTime.Now));
            Console.WriteLine(String.Format("{0:MMM}", DateTime.Now));

    static class DateTimeExtensions
        public static string ToMonthName(this DateTime dateTime)
            return CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dateTime.Month);

        public static string ToShortMonthName(this DateTime dateTime)
            return CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(dateTime.Month);


Extension Methods in Visual Studio appears with special symbol:

Extension Methods

Extension Methods

Reference: http://www.dotnetperls.com/extension


3 thoughts on “C#: Get Current Month Name and Short Name

  1. Why don’t you use:

    Console.WriteLine(String.Format(“{0:MMMM}”, DateTime.Now));
    Console.WriteLine(String.Format(“{0:MMM}”, DateTime.Now));

    • Hi Michael,

      Thank you very much for the inputs and information, I was totally unaware of these methods.

      I wanted to illustrate Extension Methods related to similar functionality. I am going to add the code to the post now.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s