beta.blog

C# – Convert month name to an Integer

by 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.


Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!