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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With