Programming
C# – Convert month name to an Integer
by admin on Jul.25, 2012, under Programming
Today I wanted to convert a month name such as January into it’s Integer value in order to easily compare it in my C# code. Initially I decided to map all month names in a Dictionary in order to get the int value of each month, but later I found an easier and probably more reliable solution.
int month = DateTime.Parse("January" + " 01, 1900").Month
This method makes it pretty easy to convert a month string into a number.