231

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.

shA.t
  • 16,580
  • 5
  • 54
  • 111

14 Answers14

342

Use the "MMMM" custom format specifier:

DateTime.Now.ToString("MMMM");
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
mservidio
  • 12,817
  • 9
  • 58
  • 84
102

You can do as mservidio suggested, or even better, keep track of your culture using this overload:

DateTime.Now.ToString("MMMM", CultureInfo.InvariantCulture);
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
emp
  • 4,926
  • 2
  • 38
  • 50
  • 3
    That's neat, I need to look into this culture stuff. – Alex Turpin Jul 20 '11 at 16:49
  • 2
    If it's only the month you're interested in then DateTime.Today instead of DateTime.Now is a further simplification. No useless time portion and a bit faster. – OrizG Dec 12 '17 at 21:58
43

If you want the current month you can use DateTime.Now.ToString("MMMM") to get the full month or DateTime.Now.ToString("MMM") to get an abbreviated month.

If you have some other date that you want to get the month string for, after it is loaded into a DateTime object, you can use the same functions off of that object:
dt.ToString("MMMM") to get the full month or dt.ToString("MMM") to get an abbreviated month.

Reference: Custom Date and Time Format Strings

Alternatively, if you need culture specific month names, then you could try these: DateTimeFormatInfo.GetAbbreviatedMonthName Method
DateTimeFormatInfo.GetMonthName Method

Alok Rajasukumaran
  • 381
  • 1
  • 5
  • 20
Jeffrey Blake
  • 9,659
  • 6
  • 43
  • 65
  • 1
    +1 for mentioning how to do it from a `DateTime` that is NOT `DateTime.Now`. I had thought it was `string mon = myDate.Month.ToString("MMM")` when I was sadly let down by it spitting "MMM" into my string variable. Glad you took the effort to show how to use `.ToString("MMM")` on the date, itself, to get the month, when it's not `DateTime.Now`. And how you explained the difference between `MMM` and `MMMM`. Best answer on this page. Kudos. – vapcguy Oct 07 '16 at 14:17
  • 1
    If it's only the month you're interested in then DateTime.Today instead of DateTime.Now is a further simplification. No useless time portion and a bit faster. – OrizG Dec 12 '17 at 21:55
39

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

Marcello B.
  • 4,177
  • 11
  • 45
  • 65
18

You can use Culture to get month name for your country like:

System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("ar-EG");
string FormatDate = DateTime.Now.ToString("dddd., MMM dd yyyy, hh:MM tt", culture);
Yehia Elhawary
  • 578
  • 1
  • 4
  • 20
17

It's

DateTime.Now.ToString("MMMM");

With 4 Ms.

shA.t
  • 16,580
  • 5
  • 54
  • 111
Alex Turpin
  • 46,743
  • 23
  • 113
  • 145
  • 1
    If it's only the month you're interested in then DateTime.Today instead of DateTime.Now is a further simplification. No useless time portion and a bit faster. – OrizG Dec 12 '17 at 21:57
13
DateTime birthDate = new DateTime(1981, 8, 9);
Console.WriteLine ("I was born on the {0}. of {1}, {2}.", birthDate.Day, birthDate.ToString("MMMM"), birthDate.Year);

/* The above code will say:
"I was born on the 9. of august, 1981."

"dd" converts to the day (01 thru 31).
"ddd" converts to 3-letter name of day (e.g. mon).
"dddd" converts to full name of day (e.g. monday).
"MMM" converts to 3-letter name of month (e.g. aug).
"MMMM" converts to full name of month (e.g. august).
"yyyy" converts to year.
*/
Madolite
  • 131
  • 1
  • 3
12

It should be just DateTime.ToString( "MMMM" )

You don't need all the extra Ms.

shA.t
  • 16,580
  • 5
  • 54
  • 111
Stefan H
  • 6,635
  • 4
  • 24
  • 35
2
Debug.writeline(Format(Now, "dd MMMM yyyy"))
Yehor Androsov
  • 4,885
  • 2
  • 23
  • 40
Fajarsoft
  • 41
  • 4
0

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);
Deb
  • 737
  • 1
  • 5
  • 20
0

if you need three month letter use "MMM"

0

Being a popular question, I stumbled upon the very same question even though my requirement was for the newer DateOnly type.

Fortunately, the same approach is applicable for the newer data type as well.

DateOnly todayDate = DateOnly.FromDateTime(DateTime.UtcNow); //27-08-2023
string fullMonthName = todayDate.ToString("MMMM");
Console.WriteLine(fullMonthName); //August
Durga Prasad
  • 939
  • 10
  • 20
-1
(DateTime = {07/01/2023 12:00:00 AM})

DateTime.ToString("MMMM")  - ( January )
Gary Bao 鲍昱彤
  • 2,608
  • 20
  • 31
  • 1
    Variants of this answer have already been provided multiple times. When answering older questions, please make sure you provide either a novel solution, or a significantly better explanation than existing answers. – Mark Rotteveel Jan 20 '23 at 11:47
-2

Use this for Full name of the month:

DateTime date = DateTime.Now;
string month = $"{date:MMMM}"; // f.g October

Use this for abbreviation name of the month:

DateTime date = DateTime.Now;
string month = $"{date:MMM}"; // f.g Oct

Use this for full name of the week:

DateTime date = DateTime.Now;
string month = $"{date:dddd}"; // f.g Saturday

Use this for abbreviation name of the week:

DateTime date = DateTime.Now;
string month = $"{date:ddd}"; // f.g Sat

You can set every custom template with this structure f.g:

DateTime date = DateTime.Now;
string month = $"{date:dd/MMM/yyyy}"; // 12/Oct/2022
string month = $"{date:dd-MM-yyyy}"; // 12-10-2022
string month = $"{date:dd MMMM yyyy}"; // 12 October 2022
string month = $"{date:ddd - - - MMM}"; // Sat - - - Oct
string month = $"{date:ddddd $- yyyy}"; // Saturday $- 2022
string month = $"{date:ddMMyyyy}"; // 12102022
Saeid
  • 422
  • 4
  • 9