How to display dynamically the previous month name

.net, asp.net, c#, datetime, string

Solution

The following should work for you:

string previousMonth = DateTime.Now.AddMonths(-1).ToString("MMMM");

If you want it in a specific language, you can pass a `CultureInfo` object to the method:

string prevMonthInFrench = DateTime.Now.AddMonths(-1).ToString("MMMM", CultureInfo.GetCultureInfo("fr-FR"));

For more options you can check the Custom Date and Time Format Strings article at MSDN.

Problem

I want to display the previous month name. My code is given below but it displays the index of that month. I want the name of that month. According to this given code it dipslays the tool tip as "Balance up to 9", but I want to display "Balance up to September". How get the name of that month? ``` lblPreviousBalance.ToolTip = "Balance up to " + (DateTime.Now.Month - 1); ```

Original source