How to get complete month name from DateTime

Viewed 379775

What is the proper way to get the complete name of month of a DateTime object?
e.g. January, December.

I am currently using:

DateTime.Now.ToString("MMMMMMMMMMMMM");

I know it's not the correct way to do it.

10 Answers

If you receive "MMMM" as a response, probably you are getting the month and then converting it to a string of defined format.

DateTime.Now.Month.ToString("MMMM") 

will output "MMMM"

DateTime.Now.ToString("MMMM") 

will output the month name

Debug.writeline(Format(Now, "dd MMMM yyyy"))

You can use the CultureInfo from System.Globalization to get that data, based on the current culture that is being used.

_ = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month)

Or, use InvariantCulture to also get the English name.

_ = CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month);
Related