Search code examples
c#datedate-conversion

C# - Best way to convert Month names to their month number


Is there a function in C# that can already change a Month name to it's corresponding month number? If not, should I make a method (like using 'Switch" or some loop function) that makes this possible?

I'm asking because I would like to have clean code and not make a huge mess in my code. Thanks in advance


Solution

  • DateTime.ParseExact(monthName, "MMMM", CultureInfo.CurrentCulture).Month